List of usage examples for java.util Calendar getTime
public final Date getTime()
Date
object representing this Calendar
's time value (millisecond offset from the Epoch"). From source file:Main.java
public static String getDate(Calendar c) { System.out.println("c: " + c); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); return df.format(c.getTime()); }
From source file:Main.java
public static Date getDateAfter(Date d, int day) { Calendar now = Calendar.getInstance(); now.setTime(d);/*from w ww . j a va2s. c o m*/ now.set(Calendar.DATE, now.get(Calendar.DATE) + day); return now.getTime(); }
From source file:Main.java
public static Date addMonth(Date date, int months) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*from w ww. java2s . c om*/ calendar.add(Calendar.MONTH, months); return calendar.getTime(); }
From source file:Main.java
public static String StampToString(long stamp) { /*//from ww w .j av a 2s. co m String[] formats = new String[] { "yyyy-MM-dd", "yyyy-MM-dd HH:mm", "yyyy-MM-dd HH:mmZ", "yyyy-MM-dd HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSSZ", }; */ Date date = null; Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(stamp); date = calendar.getTime(); String format = STAMP_TO_STRING; SimpleDateFormat sdf = new SimpleDateFormat(format); sdf.setTimeZone(TimeZone.getTimeZone(TIME_ZONE_PRC)); return sdf.format(date); }
From source file:Main.java
public static boolean isDateAfterToday(Calendar calendar) { Calendar validationCalendar = Calendar.getInstance(); validationCalendar.setTime(calendar.getTime()); validationCalendar.set(Calendar.MILLISECOND, todayCalendar.get(Calendar.MILLISECOND)); validationCalendar.set(Calendar.SECOND, todayCalendar.get(Calendar.SECOND)); validationCalendar.set(Calendar.MINUTE, todayCalendar.get(Calendar.MINUTE)); validationCalendar.set(Calendar.HOUR_OF_DAY, todayCalendar.get(Calendar.HOUR_OF_DAY)); return validationCalendar.getTime().after(todayCalendar.getTime()); }
From source file:Main.java
public static String getCurrentDate() { Calendar calander = Calendar.getInstance(); SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy"); String date = df.format(calander.getTime()); return date;/*from ww w. j a v a 2s. c o m*/ }
From source file:Main.java
public static boolean isDateBeforeToday(Calendar calendar) { Calendar validationCalendar = Calendar.getInstance(); validationCalendar.setTime(calendar.getTime()); validationCalendar.set(Calendar.MILLISECOND, todayCalendar.get(Calendar.MILLISECOND)); validationCalendar.set(Calendar.SECOND, todayCalendar.get(Calendar.SECOND)); validationCalendar.set(Calendar.MINUTE, todayCalendar.get(Calendar.MINUTE)); validationCalendar.set(Calendar.HOUR_OF_DAY, todayCalendar.get(Calendar.HOUR_OF_DAY)); return validationCalendar.getTime().before(todayCalendar.getTime()); }
From source file:Main.java
public static String getDatetime() { Calendar calendar = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_DATETIME); return sdf.format(calendar.getTime()); }
From source file:Main.java
public static String getBackupFileName() { Calendar c = Calendar.getInstance(); SimpleDateFormat format1 = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss"); return format1.format(c.getTime()) + ".txt"; }
From source file:Main.java
public static String getCurrentDateByOffset(String format, int calendarField, int offset) { String mDateTime = null;/*from w w w. j a va2s.c om*/ try { SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format, Locale.CHINA); Calendar c = Calendar.getInstance(); c.add(calendarField, offset); mDateTime = mSimpleDateFormat.format(c.getTime()); } catch (Exception e) { e.printStackTrace(); } return mDateTime; }