Java Year Month toDateProgression(int year, int month, int day, String seed, int pedometer)

Here you can find the source of toDateProgression(int year, int month, int day, String seed, int pedometer)

Description

to Date Progression

License

Apache License

Declaration

public static String toDateProgression(int year, int month, int day, String seed, int pedometer)
        throws Exception 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.DateFormat;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    private Calendar calendar;
    private static final String COLON = ":";
    private static final String ZERO = "0";

    public static String toDateProgression(int year, int month, int day, String seed, int pedometer)
            throws Exception {
        GregorianCalendar dateAntetype = new GregorianCalendar(year, month - 1, day);
        if ("year".equals(seed))
            dateAntetype.add(GregorianCalendar.YEAR, pedometer);
        else if ("month".equals(seed))
            dateAntetype.add(GregorianCalendar.MONTH, pedometer);
        else if ("day".equals(seed))
            dateAntetype.add(GregorianCalendar.DATE, pedometer);
        Date d = dateAntetype.getTime();
        DateFormat df = DateFormat.getDateInstance();
        return df.format(d);
    }/*from w ww.  j av a  2 s  .co m*/

    public String getTime() {
        return getHour() + COLON + getMinute();
    }

    public int getHour() {
        return calendar.get(Calendar.HOUR_OF_DAY);
    }

    public String getMinute() {
        int tempMinute = calendar.get(Calendar.MINUTE);
        return tempMinute < 10 ? ZERO + tempMinute : Integer.toString(tempMinute);
    }
}

Related

  1. monthBeginDate(int year, int month)
  2. newDate(int year, int month, int day)
  3. normalizeShortDate(String year, String month, String day)
  4. parseMonthAndYearStringOrNull(String dateString)
  5. sameYearAndMonth(Date d1, Date d2)
  6. toDateProgression(int year, int month, int day, String seed, int pedometer)
  7. todaySubtract(String years, String months)
  8. toYearMonth(String dateString)