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 Date getLastdayDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//from w w w .j ava 2 s . com calendar.add(Calendar.DATE, -1); return calendar.getTime(); }
From source file:Main.java
public static String getPrettyDateTime(Calendar date) { DateFormat dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT); return dateTimeFormat.format(date.getTime()); }
From source file:Main.java
public static String shortFormatTime(Calendar time) { SimpleDateFormat f = new SimpleDateFormat("EEE, h:mm a"); f.setCalendar(time);//from ww w. ja va2 s . c o m return f.format(time.getTime()); }
From source file:Main.java
public static int getYear() { Calendar calendar = Calendar.getInstance(); SimpleDateFormat yearSdf = new SimpleDateFormat("yyyy"); String yearString = yearSdf.format(calendar.getTime()); return Integer.parseInt(yearString); }
From source file:Main.java
public static Date nextMonth(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(getFirstDate(date)); calendar.add(Calendar.MONTH, 1); return calendar.getTime(); }
From source file:Main.java
public static int getMonth() { Calendar calendar = Calendar.getInstance(); SimpleDateFormat monthSdf = new SimpleDateFormat("MM"); String monthString = monthSdf.format(calendar.getTime()); return Integer.parseInt(monthString); }
From source file:Main.java
public static String getBeforeTime(int months, SimpleDateFormat format, Date now) { Calendar calendar = Calendar.getInstance(); calendar.setTime(now);//from w w w .ja v a 2s . c o m calendar.add(calendar.MONTH, -months); return format.format(calendar.getTime()); }
From source file:Main.java
public static String getCurrentDateTime() { Calendar c = Calendar.getInstance(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return df.format(c.getTime()); }
From source file:Main.java
public static Date firstDateOfNextMonth(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//from ww w. j a va 2 s. c o m calendar.add(Calendar.MONTH, 1); Date newDate = calendar.getTime(); return firstDateOfMonth(newDate); }
From source file:Main.java
public static String now() { Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.CHINA); return sdf.format(cal.getTime()); }