List of usage examples for java.util Calendar setTime
public final void setTime(Date date)
Date
. From source file:Main.java
private static Date getDateBefore() { Date nowtime = new Date(); Calendar now = Calendar.getInstance(); now.setTime(nowtime); now.set(Calendar.DATE, now.get(Calendar.DATE) - LOG_SAVE_DAYS); return now.getTime(); }
From source file:Main.java
public static String getNextDateByNum(String s, int i) { SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMdd"); java.util.Date date = simpledateformat.parse(s, new ParsePosition(0)); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(5, i);//from w ww.j a va 2 s.c o m date = calendar.getTime(); s = simpledateformat.format(date); return s; }
From source file:Main.java
public static boolean isSameDay(String s1, String s2) { if (s1 == null || s2 == null) return false; Calendar c1 = Calendar.getInstance(); c1.setTime(new Date(Long.parseLong(s1))); Calendar c2 = Calendar.getInstance(); c2.setTime(new Date(Long.parseLong(s2))); return isSameDay(c1, c2); }
From source file:Main.java
public static Date firstDateOfNextMonth(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.MONTH, 1); Date newDate = calendar.getTime(); return firstDateOfMonth(newDate); }
From source file:Main.java
public static String getNextDateByYear(String s, int i) { SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMdd"); java.util.Date date = simpledateformat.parse(s, new ParsePosition(0)); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.YEAR, i); date = calendar.getTime();//from w w w . j a v a 2 s . c om s = simpledateformat.format(date); return s; }
From source file:Main.java
public static Date dayBegin(final Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0);//from ww w .j a v a2s . c o m c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTime(); }
From source file:Main.java
public static Date dayEnd(final Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59);/*from w w w .j a v a 2s. c om*/ c.set(Calendar.SECOND, 59); c.set(Calendar.MILLISECOND, 999); return c.getTime(); }
From source file:Main.java
public static long formatToLong(String time, String template) { SimpleDateFormat sdf = new SimpleDateFormat(template, Locale.CHINA); try {/*from ww w .ja v a 2 s. co m*/ Date d = sdf.parse(time); Calendar c = Calendar.getInstance(); c.setTime(d); long l = c.getTimeInMillis(); return l; } catch (ParseException e) { e.printStackTrace(); return 0; } }
From source file:Main.java
public static Date getDate(final Date aDate) { try {//from w w w . j ava2 s .c o m Calendar calDate = Calendar.getInstance(); calDate.setTime(aDate); return calDate.getTime(); } catch (Exception ex) { System.out.println("HelperTool.getDate(): " + ex.toString()); return null; } }
From source file:Main.java
public static boolean isToday(long date) { Calendar compareCalendar = Calendar.getInstance(); compareCalendar.setTime(new Date(date)); Calendar todayCalendar = Calendar.getInstance(); todayCalendar.setTime(new Date(System.currentTimeMillis())); return todayCalendar.get(Calendar.DATE) == compareCalendar.get(Calendar.DATE); }