Example usage for java.util Calendar get

List of usage examples for java.util Calendar get

Introduction

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

Prototype

public int get(int field) 

Source Link

Document

Returns the value of the given calendar field.

Usage

From source file:Main.java

/**
 * Returns <tt>true</tt> if the two given calendars are dated on the same year.
 * @param one The one calendar./*from w w  w  .  ja  v a2s  .  co  m*/
 * @param two The other calendar.
 * @return True if the two given calendars are dated on the same year.
 */
public static boolean sameYear(Calendar one, Calendar two) {
    return one.get(Calendar.YEAR) == two.get(Calendar.YEAR);
}

From source file:Main.java

public static int getWeekInChina(Calendar calendar) {
    int week = calendar.get(Calendar.WEEK_OF_YEAR);
    int day = calendar.get(Calendar.DAY_OF_WEEK);
    if (day == 1) {
        week = week - 1;/*from ww  w.  ja v  a 2 s. co  m*/
    }
    return week;
}

From source file:Main.java

/**
 * Builds a simple hash for a day by concatenating year and day of year together. Note that two
 * {@link java.util.Calendar} inputs that fall on the same day will be hashed to the same
 * string./* w  w  w  .j a  va 2 s  . co  m*/
 */
public static String getHashedDay(Calendar day) {
    return day.get(Calendar.YEAR) + "-" + day.get(Calendar.DAY_OF_YEAR);
}

From source file:Main.java

public static String getDateTime(Calendar calendar) {
    int year = calendar.get(Calendar.YEAR);
    //  if (year>3900) year-=1900;
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
    //Date date = new Date();
    return dateFormat
            .format(new Date(year - 1900, calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)));
}

From source file:Main.java

public static String getDateTimeString(Calendar calendar) {
    int year = calendar.get(Calendar.YEAR);
    //  if (year>3900) year-=1900;
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.getDefault());
    //Date date = new Date();
    return dateFormat
            .format(new Date(year - 1900, calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)));
}

From source file:Main.java

public static int getYear(Calendar calendar) {
    return calendar.get(YEAR);
}

From source file:Main.java

public static int getMonth(Calendar calendar) {
    return calendar.get(MONTH);
}

From source file:Main.java

public static int getWeekOfYear() {
    Calendar now = Calendar.getInstance();
    return now.get(Calendar.WEEK_OF_YEAR);
}

From source file:Main.java

public static String getTodaysDate() {
    Calendar c = Calendar.getInstance();
    return c.get(Calendar.YEAR) + "-0" + String.valueOf(c.get(Calendar.MONTH) + 1) + "-"
            + c.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static boolean checkFirstDayOfMonth() {
    Calendar c = Calendar.getInstance();
    return (c.get(Calendar.DATE) == 1);
}