List of usage examples for java.util Calendar get
public int get(int field)
From source file:Main.java
public static Date getNextSaturday(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);//from w w w. j a v a 2 s . c o m while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) { cal.add(Calendar.DAY_OF_WEEK, 1); } return cal.getTime(); }
From source file:Main.java
public static int getWeekOfDate(Date dt) { Calendar cal = Calendar.getInstance(); cal.setTime(dt);//from ww w . j ava 2 s.c om int w = cal.get(Calendar.DAY_OF_WEEK) - 1; if (w < 0) w = 0; return w; }
From source file:Main.java
private static Boolean isThisDayOfMonth(Calendar calendar) { Calendar nowCalendar = Calendar.getInstance(); return calendar.get(Calendar.DAY_OF_MONTH) == nowCalendar.get(Calendar.DAY_OF_MONTH); }
From source file:Main.java
public static Date getNextMonday(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);//from w ww. ja va 2s.c o m while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { cal.add(Calendar.DAY_OF_WEEK, 1); } return cal.getTime(); }
From source file:Main.java
public static int getDayOfWeek() { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); return cal.get(Calendar.DAY_OF_WEEK) - 1; }
From source file:Main.java
private static Boolean isThisMonth(Calendar calendar) { Calendar nowCalendar = Calendar.getInstance(); return calendar.get(Calendar.MONTH) == nowCalendar.get(Calendar.MONTH); }
From source file:Main.java
/** * Get number of month difference with the current month * @param year/*from ww w . j av a 2 s. com*/ * @param month * @return */ public static int getMonthDifference(int year, int month) { Calendar cal = Calendar.getInstance(); int currentMonth = cal.get(Calendar.MONTH); int currentYear = cal.get(Calendar.YEAR); return (currentYear - year) * 12 + currentMonth - month; }
From source file:Main.java
public static int getDayOfMonth() { Calendar c = Calendar.getInstance(); c.setTime(new Date()); int year = c.get(Calendar.DAY_OF_MONTH); return year;/* w w w . j av a 2 s. c o m*/ }
From source file:Main.java
public static String getCurrentTimeStampDD_MM_HH_MM() { Calendar cal = new GregorianCalendar(); return makeTimeString(cal.get(Calendar.DAY_OF_MONTH), 2) + "." + makeTimeString(cal.get(Calendar.MONTH) + 1, 2) + ". " + makeTimeString(cal.get(Calendar.HOUR_OF_DAY), 2) + ":" + makeTimeString(cal.get(Calendar.MINUTE), 2); }
From source file:Main.java
public static int getYear() { Calendar c = Calendar.getInstance(); c.setTime(new Date()); int year = c.get(Calendar.YEAR); return year;/* www. j a v a 2s .c o m*/ }