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 Calendar getTodayAt(int hours, int minutes) {
    Calendar today = Calendar.getInstance();
    Calendar cal = Calendar.getInstance();
    cal.clear();//from  ww  w.  j  a  v  a2s  . co  m

    int year = today.get(Calendar.YEAR);
    int month = today.get(Calendar.MONTH);
    //represents the day of the month
    int day = today.get(Calendar.DATE);
    cal.set(year, month, day, hours, minutes, 0);
    return cal;
}

From source file:Main.java

/**
 * @return Return current year (IE 2015, 2016)
 *//*from  ww w.  j  a  v a 2s  .co m*/
public static int getCurrentYear() {
    Calendar cal = Calendar.getInstance();
    int year = cal.get(Calendar.YEAR);
    return year;
}

From source file:Main.java

public static String getShortMonthYearDisplay(Calendar cal) {
    return cal.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US) + " " + cal.get(Calendar.YEAR);
}

From source file:Main.java

public static Calendar getTomorrowAt(int hours, int minutes) {
    Calendar today = Calendar.getInstance();
    Calendar cal = Calendar.getInstance();
    cal.clear();/*from  ww w.  j  a  v  a 2 s .  c  o  m*/

    int year = today.get(Calendar.YEAR);
    int month = today.get(Calendar.MONTH);
    //represents the day of the month
    today.add(Calendar.DATE, 1);
    int day = today.get(Calendar.DATE);
    cal.set(year, month, day, hours, minutes, 0);
    return cal;
}

From source file:Main.java

public static String getTodayYYYYMMDD() {
    Calendar calendar = Calendar.getInstance();
    StringBuffer sbDate = new StringBuffer();
    int nYear, nMonth, nDay;
    nYear = calendar.get(Calendar.YEAR);
    nMonth = calendar.get(Calendar.MONTH) + 1;
    nDay = calendar.get(Calendar.DAY_OF_MONTH);
    sbDate.append(nYear);/*from w w  w. j a v a2 s  .  c  o  m*/
    if (nMonth < 10)
        sbDate.append("0");
    sbDate.append(nMonth);
    if (nDay < 10)
        sbDate.append("0");
    sbDate.append(nDay);

    return sbDate.toString();
}

From source file:Main.java

public static final int getYearByMill(long mill) {
    Date curDate = new Date(mill);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(curDate);/*from  w  w w.ja va  2s .co  m*/
    return calendar.get(java.util.Calendar.YEAR);
}

From source file:Main.java

/**
 * Return if the two calendar is in the same day, ignoring time
 * @param day1// ww  w. j a  v  a  2 s  .  c o  m
 * @param day2
 * @return
 */
public static boolean isSameDay(Calendar day1, Calendar day2) {
    return day1.get(Calendar.YEAR) == day2.get(Calendar.YEAR)
            && day1.get(Calendar.MONTH) == day2.get(Calendar.MONTH)
            && day1.get(Calendar.DAY_OF_MONTH) == day2.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

/**
 * Returns current date-time in format of yyyy-MM-dd hh:mm:ss
 * /* w w w .ja  v a 2  s  . c  o  m*/
 * @return date time in string.
 */
public static String getCurrentTime() {
    int yyyy = Calendar.getInstance().get(Calendar.YEAR);
    int MM = Calendar.getInstance().get(Calendar.MONTH) + 1;
    int dd = Calendar.getInstance().get(Calendar.DATE);
    int hh = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
    int mm = Calendar.getInstance().get(Calendar.MINUTE);
    int ss = Calendar.getInstance().get(Calendar.SECOND);
    String curDate = String.format("%04d-%02d-%02d %02d:%02d:%02d", yyyy, MM, dd, hh, mm, ss);

    return curDate;

}

From source file:Main.java

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

From source file:Main.java

public static boolean isSameYear(Date targetTime, Date compareTime) {
    Calendar tarCalendar = Calendar.getInstance();
    tarCalendar.setTime(targetTime);/*from  w  w  w .j  av  a  2  s .  c o m*/
    int tarYear = tarCalendar.get(Calendar.YEAR);

    Calendar compareCalendar = Calendar.getInstance();
    compareCalendar.setTime(compareTime);
    int comYear = compareCalendar.get(Calendar.YEAR);

    return tarYear == comYear;
}