List of usage examples for java.util Calendar setTime
public final void setTime(Date date)
Date
. From source file:Main.java
/** * @param date//from w w w. j a v a2 s .co 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 Date addMonth(Date date, int months) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.MONTH, months); return calendar.getTime(); }
From source file:Main.java
public static int getNextMonthDays(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); c.add(Calendar.MONTH, 1);// ww w . j a v a 2 s . c o m return c.getActualMaximum(Calendar.DAY_OF_MONTH); }
From source file:Main.java
public static java.util.Date getDateEnd(java.util.Date d) { Calendar c = Calendar.getInstance(); c.clear();/* w w w. j a v a2s .c om*/ Calendar co = Calendar.getInstance(); co.setTime(d); c.set(Calendar.DAY_OF_MONTH, co.get(Calendar.DAY_OF_MONTH)); c.set(Calendar.MONTH, co.get(Calendar.MONTH)); c.set(Calendar.YEAR, co.get(Calendar.YEAR)); c.add(Calendar.DAY_OF_MONTH, 1); c.add(Calendar.MILLISECOND, -1); return c.getTime(); }
From source file:Main.java
public static Date getFirstDayOfMonth(Date dateTime) { if (dateTime == null) return dateTime; Calendar calendar = Calendar.getInstance(); calendar.setTime(dateTime); calendar.set(Calendar.DAY_OF_MONTH, 1); return calendar.getTime(); }
From source file:Main.java
public static int getUpMonth(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); c.add(Calendar.MONTH, -1);/* w w w. j av a2 s. co m*/ return c.get(Calendar.MONTH); }
From source file:Main.java
public static String getTomorrowDate() { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); Date date = new Date(System.currentTimeMillis()); Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.DAY_OF_YEAR, +1); return sdf.format(cal.getTime()); }
From source file:Main.java
public static int getNextMonth(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); c.add(Calendar.MONTH, 1);//from ww w . j a v a 2 s . c o m return c.get(Calendar.MONTH); }
From source file:Main.java
public static Date addDate(Date date, int days) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.DATE, days); return calendar.getTime(); }
From source file:Main.java
public static Date getStartOfDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); return calendar.getTime(); }