Example usage for java.util Calendar YEAR

List of usage examples for java.util Calendar YEAR

Introduction

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

Prototype

int YEAR

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

Click Source Link

Document

Field number for get and set indicating the year.

Usage

From source file:Main.java

public static long getEndOfDayMs(int year, int month, int day) {
    final Calendar date = Calendar.getInstance();

    date.set(Calendar.YEAR, year);
    date.set(Calendar.MONTH, month);
    date.set(Calendar.DAY_OF_MONTH, day);
    date.set(Calendar.HOUR_OF_DAY, date.getActualMaximum(Calendar.HOUR_OF_DAY));
    date.set(Calendar.MINUTE, date.getActualMaximum(Calendar.MINUTE));
    date.set(Calendar.SECOND, date.getActualMaximum(Calendar.SECOND));
    date.set(Calendar.MILLISECOND, date.getActualMaximum(Calendar.MILLISECOND));
    return date.getTimeInMillis();
}

From source file:Main.java

public static long getStartOfDayMs(int year, int month, int day) {
    final Calendar date = Calendar.getInstance();

    date.set(Calendar.YEAR, year);
    date.set(Calendar.MONTH, month);
    date.set(Calendar.DAY_OF_MONTH, day);
    date.set(Calendar.HOUR_OF_DAY, date.getActualMinimum(Calendar.HOUR_OF_DAY));
    date.set(Calendar.MINUTE, date.getActualMinimum(Calendar.MINUTE));
    date.set(Calendar.SECOND, date.getActualMinimum(Calendar.SECOND));
    date.set(Calendar.MILLISECOND, date.getActualMinimum(Calendar.MILLISECOND));
    return date.getTimeInMillis();
}

From source file:Main.java

public static String toYYYYMMDDHHMMSS(Calendar source) {
    if (source == null) {
        return "Can't toYYYYMMDDHHMMSS source null";
    }/*  w  w  w  .j  av a2 s. c  o  m*/
    int YYYY = source.get(Calendar.YEAR);
    int MM = source.get(Calendar.MONTH);
    int DD = source.get(Calendar.DAY_OF_MONTH);
    int HH = source.get(Calendar.HOUR_OF_DAY);
    int mm = source.get(Calendar.MINUTE);
    int SS = source.get(Calendar.SECOND);

    return YYYY + "-" + MM + "-" + DD + " " + HH + ":" + mm + ":" + SS;
}

From source file:Main.java

public static Date getDate(int year, int month, int day) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, day);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);/*  ww  w  .  j a  va  2s.  com*/
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}

From source file:Main.java

public static boolean isBefore(Calendar currentCalendar, Calendar max) {
    int currentYear = currentCalendar.get(Calendar.YEAR);
    int currentMonth = currentCalendar.get(Calendar.MONTH);
    int currentDay = currentCalendar.get(Calendar.DAY_OF_MONTH);
    int maxYear = max.get(Calendar.YEAR);
    int maxMonth = max.get(Calendar.MONTH);
    int maxDay = max.get(Calendar.DAY_OF_MONTH);
    Log.i("TAG",/*  www .ja  v a  2s  .co  m*/
            (currentYear <= maxYear && currentMonth <= maxMonth && currentDay <= maxDay) + "currentYear"
                    + currentYear + "maxYear" + maxYear + "currentMonth" + currentMonth + "maxMonth" + maxMonth
                    + "currentDay" + currentDay + "maxDay" + maxDay);
    return (currentYear == maxYear)
            ? ((currentMonth == currentMonth) ? (currentDay < maxDay) : (currentMonth < maxMonth))
            : (currentYear < maxYear);
}

From source file:Main.java

public static int getYear(Date date) {
    calendar = Calendar.getInstance();
    calendar.setTime(date);
    return calendar.get(Calendar.YEAR);
}

From source file:Main.java

public static boolean inSameDay(Date date1, Date Date2) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date1);/*from w  ww  .  j a v a  2  s  . co  m*/
    int year1 = calendar.get(Calendar.YEAR);
    int day1 = calendar.get(Calendar.DAY_OF_YEAR);

    calendar.setTime(Date2);
    int year2 = calendar.get(Calendar.YEAR);
    int day2 = calendar.get(Calendar.DAY_OF_YEAR);

    return (year1 == year2) && (day1 == day2);
}

From source file:Main.java

public static boolean isDateInCurrentYear(long date) {
    Calendar currentCalendar = getCurrentCalendar();
    int year = currentCalendar.get(Calendar.YEAR);

    Calendar targetCalendar = getCalendarWithTime(date);
    int targetYear = targetCalendar.get(Calendar.YEAR);

    return (year == targetYear);
}

From source file:Main.java

public static String getCurrentTime() {
    DecimalFormat df = new DecimalFormat("00");
    Calendar c = Calendar.getInstance();
    String currentTime = c.get(Calendar.YEAR)// + "-"
            + df.format((c.get(Calendar.MONTH) + 1)) // + "-"
            + df.format(c.get(Calendar.DAY_OF_MONTH))// + "-"
            + df.format(c.get(Calendar.HOUR_OF_DAY)) // + "-"
            + df.format(c.get(Calendar.MINUTE))// + "-"
            + df.format(c.get(Calendar.SECOND));
    return currentTime;
}

From source file:Main.java

public static String getCurrentDateString() {
    Calendar date = Calendar.getInstance();
    int day = date.get(Calendar.DATE);
    int month = (date.get(Calendar.MONTH)) + 1;
    int year = date.get(Calendar.YEAR);
    String dateString = month + "-" + day + "-" + year;
    return dateString;
}