Example usage for java.util Calendar MONTH

List of usage examples for java.util Calendar MONTH

Introduction

In this page you can find the example usage for java.util Calendar MONTH.

Prototype

int MONTH

To view the source code for java.util Calendar MONTH.

Click Source Link

Document

Field number for get and set indicating the month.

Usage

From source file:Main.java

public static boolean isAfterADay(Calendar newCalendar, Calendar oldCalendar) {
    Log.d("TEST", "run isAferDay");
    if (newCalendar.get(Calendar.YEAR) > oldCalendar.get(Calendar.YEAR))
        return true;
    if (newCalendar.get(Calendar.YEAR) == oldCalendar.get(Calendar.YEAR)
            && newCalendar.get(Calendar.MONTH) > oldCalendar.get(Calendar.MONTH))
        return true;
    if (newCalendar.get(Calendar.YEAR) == oldCalendar.get(Calendar.YEAR)
            && newCalendar.get(Calendar.MONTH) == oldCalendar.get(Calendar.MONTH)
            && newCalendar.get(Calendar.DAY_OF_MONTH) > oldCalendar.get(Calendar.DAY_OF_MONTH))
        return true;
    return false;
}

From source file:Main.java

public static String getDateString() {
    String stringDate = "";
    Calendar calendar = Calendar.getInstance();
    int day = calendar.get(Calendar.DAY_OF_WEEK);
    int month = calendar.get(Calendar.MONTH);
    int dayInt = calendar.get(Calendar.DAY_OF_MONTH);
    switch (day) {
    case Calendar.SUNDAY:
        stringDate += "Sunday";
        break;/*from w  ww .j  ava  2s  .c  o  m*/

    case Calendar.MONDAY:
        stringDate += "Monday";
        break;

    case Calendar.TUESDAY:
        stringDate += "Tuesday";
        break;

    case Calendar.WEDNESDAY:
        stringDate += "Wednesday";
        break;

    case Calendar.THURSDAY:
        stringDate += "Thursday";
        break;

    case Calendar.FRIDAY:
        stringDate += "Friday";
        break;

    case Calendar.SATURDAY:
        stringDate += "Saturday";
        break;

    }
    switch (month) {
    case Calendar.JANUARY:
        stringDate += ", January";
        break;

    case Calendar.FEBRUARY:
        stringDate += ", February";
        break;

    case Calendar.MARCH:
        stringDate += ", March";
        break;

    case Calendar.APRIL:
        stringDate += ", April";
        break;

    case Calendar.MAY:
        stringDate += ", May";
        break;

    case Calendar.JUNE:
        stringDate += ", June";
        break;

    case Calendar.JULY:
        stringDate += ", July";
        break;

    case Calendar.AUGUST:
        stringDate += ", August";
        break;

    case Calendar.SEPTEMBER:
        stringDate += ", September";
        break;

    case Calendar.OCTOBER:
        stringDate += ", October";
        break;

    case Calendar.NOVEMBER:
        stringDate += ", November";
        break;

    case Calendar.DECEMBER:
        stringDate += ", December";
        break;

    }

    stringDate += (" " + dayInt);

    return stringDate;
}

From source file:Main.java

public static String getToday() {
    Calendar calendar = Calendar.getInstance();
    int month = calendar.get(Calendar.MONTH) + 1;
    return calendar.get(Calendar.YEAR) + "-" + ((month < 10) ? "0" + month : "" + month) + "-"
            + calendar.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static boolean hasMonthPassed(int year, int month) {
    Calendar now = Calendar.getInstance();
    // Expires at end of specified month, Calendar month starts at 0
    return hasYearPassed(year)
            || normalizeYear(year) == now.get(Calendar.YEAR) && month < (now.get(Calendar.MONTH) + 1);
}

From source file:Main.java

/**
 * Returns two days old date from the current date. This is used with forusquare web service to get the data
 * according to date./*ww w .  j  ava 2  s .c  o m*/
 * 
 * @return date in string.
 */
public static String getTwoDaysOldDate() {

    int yyyy = Calendar.getInstance().get(Calendar.YEAR);
    int MM = Calendar.getInstance().get(Calendar.MONTH) + 1;
    int dd = Calendar.getInstance().get(Calendar.DATE) - 2;
    Calendar cal = Calendar.getInstance();
    if (dd < 1) {
        MM = MM - 1;
        if (MM < 0) {
            MM = 0;
        }
    }

    if (MM < 0) {
        yyyy = yyyy - 1;
    }
    cal.set(yyyy, MM, 1);
    dd = cal.getActualMaximum(Calendar.DATE) - dd;
    String oldDate = String.format("%04d%02d%02d", yyyy, MM, dd);

    return oldDate;
}

From source file:Main.java

public static String getMonth(final Date date) {
    if (date != null) {
        Calendar calendar = Calendar.getInstance();
        TimeZone timeZone = TimeZone.getTimeZone("GMT+8");
        calendar.setTimeZone(timeZone);//from w w w .  j av a  2  s  . co  m
        calendar.setTime(date);
        return String.valueOf(calendar.get(Calendar.MONTH) + 1);
    }
    return "0";
}

From source file:Main.java

public static int compareDate(Calendar time1, Calendar time2) {
    int result = -1;
    if (time1.getTimeInMillis() == time2.getTimeInMillis()) {
        result = 0;/*from  w w w.  ja  v  a 2 s . c  o  m*/
    } else if (time1.get(Calendar.YEAR) == time2.get(Calendar.YEAR)) {
        result = 6;
        if (time1.get(Calendar.MONTH) == time2.get(Calendar.MONDAY)) {
            result = 5;
            if (time1.get(Calendar.DAY_OF_MONTH) == time2.get(Calendar.DAY_OF_MONTH)) {
                result = 4;
                if (time1.get(Calendar.HOUR_OF_DAY) == time2.get(Calendar.HOUR_OF_DAY)) {
                    result = 3;
                    if (time1.get(Calendar.MINUTE) == time2.get(Calendar.MINUTE)) {
                        result = 2;
                        if (time1.get(Calendar.SECOND) == time2.get(Calendar.SECOND)) {
                            result = 1;
                        }
                    }
                }
            }
        }
    } else if (time1.get(Calendar.YEAR) / 100 == time2.get(Calendar.YEAR) / 100) {
        result = 7;
    }
    return result;
}

From source file:Main.java

public static Bundle bundleCalendar(Calendar cal) {
    Bundle args = new Bundle();
    if (cal == null)
        cal = Calendar.getInstance(Locale.getDefault());
    ;/*w  ww  .  j av  a2  s .  co  m*/
    args.putInt("year", cal.get(Calendar.YEAR));
    args.putInt("month", cal.get(Calendar.MONTH));
    args.putInt("day", cal.get(Calendar.DAY_OF_MONTH));
    args.putInt("hour", cal.get(Calendar.HOUR_OF_DAY));
    args.putInt("minute", cal.get(Calendar.MINUTE));
    return args;
}

From source file:Main.java

public static Calendar getDateAwareCalendar() {
    Calendar calendar = new GregorianCalendar();

    // Check if the 1st of September is in two weeks. If so we need to download full timetable
    // for two weeks beginning from the 1st of September in advance.
    if (calendar.get(Calendar.MONTH) == Calendar.AUGUST && calendar.get(Calendar.DATE) >= 18) {
        calendar.set(Calendar.MONTH, Calendar.SEPTEMBER);
        calendar.set(Calendar.DATE, 1);
    }//from w  w w  .  j  a  v  a 2 s. c om

    prepareCalendarNoSunday(calendar);
    return calendar;
}

From source file:Main.java

public static List<String> getWeekDate() {
    List<String> list = new ArrayList<String>();
    Calendar calendar = Calendar.getInstance(Locale.CHINA);
    calendar.setTime(new Date());
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    list.add(calendar.get(Calendar.MONTH) + 1 + "." + calendar.get(Calendar.DATE));
    for (int i = 0; i < 6; i++) {
        calendar.add(Calendar.DATE, 1);
        String str = calendar.get(Calendar.MONTH) + 1 + "." + calendar.get(Calendar.DATE);
        list.add(str);// ww  w.  j a  va  2s  .c  o m
    }
    return list;
}