List of usage examples for java.util Calendar get
public int get(int field)
From source file:Main.java
private static Date getStartWeekOfMonth(int year, int month) { Calendar c = Calendar.getInstance(); c.set(year, month - 1, 1);/*from w ww. j a v a 2 s .c o m*/ int week = c.get(Calendar.DAY_OF_WEEK); return getDistanceDate(c.getTime(), 1 - week); }
From source file:Main.java
public static String getDateDisplay(Calendar cal) { return cal.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.US) + " " + cal.get(Calendar.DATE) + ", " + cal.get(Calendar.YEAR); }
From source file:Main.java
public static Date startOfThisMonth(int startDayOfMonth) { Calendar cal = Calendar.getInstance(); if (cal.get(Calendar.DATE) < startDayOfMonth) // the start is startDayOfMonth, last month cal.add(Calendar.MONTH, -1); int lastDayInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH); if (startDayOfMonth <= lastDayInMonth) cal.set(Calendar.DATE, startDayOfMonth); else {//from w ww .j a v a 2 s .c o m cal.add(Calendar.MONTH, 1); cal.set(Calendar.DATE, 1); } return startOfDay(cal.getTime()); }
From source file:Main.java
public static Date startOfNextMonth(int startDayOfMonth) { Calendar cal = Calendar.getInstance(); if (cal.get(Calendar.DATE) >= startDayOfMonth)// the end is one day past startDayOfMonth, next month cal.add(Calendar.MONTH, 1); int lastDayInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH); if (startDayOfMonth < lastDayInMonth) cal.set(Calendar.DATE, startDayOfMonth + 1); else {/* ww w . ja v a2 s . c o m*/ cal.add(Calendar.MONTH, 1); cal.set(Calendar.DATE, 1); } return startOfDay(cal.getTime()); }
From source file:Main.java
public static int getMonthOfYear(long date) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(date);// w w w.ja va2 s . c o m return c.get(Calendar.MONTH); }
From source file:Main.java
public static int getDayOfMonth(long date) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(date);// www . j av a 2 s . c o m return c.get(Calendar.DAY_OF_MONTH); }
From source file:Main.java
@Deprecated public static int getMonthOfMonth(int y, int m) { Calendar calendar = Calendar.getInstance(); calendar.set(y, m - 1, 1);/* www .ja v a 2 s. c om*/ int month = calendar.get(Calendar.MONTH); return month + 1; }
From source file:Main.java
/** * ????date???n???????/* w w w . j a v a 2s . c o m*/ */ public static Date getDateAfter(Date date, int n) { Calendar now = Calendar.getInstance(); now.setTime(date); now.set(Calendar.DATE, now.get(Calendar.DATE) + n); return now.getTime(); }
From source file:Util.java
public static int getDayOfMonthFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*w w w . j ava2 s .c om*/ return calendar.get(Calendar.DAY_OF_MONTH); }
From source file:Util.java
public static int getMonthFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*from ww w . j a va 2 s . c o m*/ return calendar.get(Calendar.MONTH); }