List of usage examples for java.util Calendar get
public int get(int field)
From source file:Main.java
public static int getMinute(long date) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(date);/* ww w . j a v a 2s . c o m*/ return c.get(Calendar.MINUTE); }
From source file:Main.java
public static int getHourOfDay(long date) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(date);//from w ww . j a v a 2 s.c o m return c.get(Calendar.HOUR_OF_DAY); }
From source file:Main.java
/** * @param date/* w ww .j a va2 s . c o m*/ * @param ele, the Field of Calendar * @return */ public static int getDateElement(Date date, int ele) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar.get(ele); }
From source file:Main.java
public static int getWeekdayOfFirstDayOfMonth(int year, int month) { int dayOfWeek = -1; Calendar cal = Calendar.getInstance(); cal.set(year, month - 1, 1);// ww w . j av a2 s. c om dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); return dayOfWeek - 1; }
From source file:Main.java
public static boolean isDatesInSameMonth(long lhs, long rhs) { Calendar lhsCalendar = getCalendarWithTime(lhs); int lhsMonth = lhsCalendar.get(Calendar.MONTH); int lhsYear = lhsCalendar.get(Calendar.YEAR); Calendar rhsCalendar = getCalendarWithTime(rhs); int rhsMonth = rhsCalendar.get(Calendar.MONTH); int rhsYear = rhsCalendar.get(Calendar.YEAR); return (lhsMonth == rhsMonth) && (lhsYear == rhsYear); }
From source file:Main.java
static Calendar toNearestWholeHour(Calendar d) { Calendar c = new GregorianCalendar(); c.setTime(d.getTime());/*from w ww.java 2 s . c o m*/ if (c.get(Calendar.MINUTE) >= 30) c.add(Calendar.HOUR, 1); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); return c; }
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 boolean isTodayInCalendar(Calendar calendar) { return todayCalendar.get(Calendar.DAY_OF_MONTH) == calendar.get(Calendar.DAY_OF_MONTH) && todayCalendar.get(Calendar.MONTH) == calendar.get(Calendar.MONTH) && todayCalendar.get(Calendar.YEAR) == calendar.get(Calendar.YEAR); }
From source file:Main.java
/** * Is a dateTime after tomorrow//from ww w . j av a 2s .c o m * @param dateTimeString in format 2012-10-15T08:17:00 * @return true if not today or tomorrow * */ public static String isAfterTomorrow(String dateTime) { Calendar depDate = parseCalendarString(dateTime); int month = depDate.get(Calendar.MONTH) + 1; int day = depDate.get(Calendar.DAY_OF_MONTH); return day + "/" + month; }
From source file:Main.java
public static String getShortDateDisplay(Calendar cal) { return cal.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US) + " " + cal.get(Calendar.DATE); }