List of usage examples for java.util Calendar setTime
public final void setTime(Date date)
Date
. From source file:Main.java
public static Date getMidnight(Date date) { Calendar day = Calendar.getInstance(); day.setTime(date); day.set(Calendar.HOUR_OF_DAY, 0); day.set(Calendar.MINUTE, 0);// w ww. j a va2 s . co m day.set(Calendar.SECOND, 0); day.set(Calendar.MILLISECOND, 0); day.add(Calendar.DAY_OF_MONTH, 0); return day.getTime(); }
From source file:Main.java
public static Date getCeilDate(Date d) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date(d.getTime() + 1000 * 60 * 60)); // Set time fields to zero cal.set(Calendar.MINUTE, 0);//from ww w . j a v a 2s. c o m cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); }
From source file:Main.java
public static String getFormatDateAdd(Date date, int amount, String format) { Calendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(GregorianCalendar.DATE, amount); return getFormatDateTime(cal.getTime(), format); }
From source file:Main.java
public static boolean IsDiferentDate(Date date1, Date date2) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date1); int daysInYear1 = calendar.get(Calendar.DAY_OF_YEAR); calendar = Calendar.getInstance(); calendar.setTime(date2);/*from w w w . j a v a 2s .c o m*/ int daysInYear2 = calendar.get(Calendar.DAY_OF_YEAR); if (daysInYear1 != daysInYear2 || date1.getYear() != date2.getYear()) { return true; } return false; }
From source file:Main.java
public static int getWeekOfDate() { Calendar calendar = Calendar.getInstance(Locale.CHINA); calendar.setTime(new Date()); int k = calendar.get(Calendar.DAY_OF_WEEK) - 1; if (k < 1) k = 7;/*from w ww.java 2 s .com*/ return k; }
From source file:Main.java
public static Date getFloorDate(Date d) { Calendar cal = Calendar.getInstance(); cal.setTime(d); // Set time fields to zero cal.set(Calendar.MINUTE, 0);// w ww .j a v a 2 s. co m cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); }
From source file:Main.java
public static XMLGregorianCalendar convertDate(Date date) { try {/*w w w . ja v a2 s .co m*/ Calendar c = new GregorianCalendar(); c.setTime(date); XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(); xmlGregorianCalendar.setDay(c.get(Calendar.DAY_OF_MONTH)); xmlGregorianCalendar.setMonth(c.get(Calendar.MONTH)); xmlGregorianCalendar.setYear(c.get(Calendar.YEAR)); return xmlGregorianCalendar; } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } }
From source file:Main.java
/** * @param date//from w w w. j a va2s .c om * @return Returns year of the argument date. */ private static String getYearFromDate(Date date) { if (date == null) { return null; } Calendar cal = Calendar.getInstance(); cal.setTime(date); return String.valueOf(cal.get(Calendar.YEAR)); }
From source file:Main.java
public static Date getNextdayDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.DATE, 1); return calendar.getTime(); }
From source file:Main.java
public static Date getLastdayDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.DATE, -1); return calendar.getTime(); }