List of usage examples for java.text SimpleDateFormat format
public final String format(Date date)
From source file:Main.java
public static String formatDate(Date date, String format) { if (date == null) { return null; }/*from w ww .j av a 2s .co m*/ SimpleDateFormat fmt = new SimpleDateFormat(format); return fmt.format(date); }
From source file:Main.java
public static String getCurrentTimeString() { SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); return formatter.format(new Date()); }
From source file:Main.java
public static String generateFilenameString() { SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); return df.format(new Date()) + "_" + new Random().nextInt(1000); }
From source file:Main.java
public static String dateToString(Date date, String format) { SimpleDateFormat sDateFormat = new SimpleDateFormat(format); return sDateFormat.format(date); }
From source file:Main.java
public static String formatDateYYYYMMDD() { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); return sdf.format(new Date()); }
From source file:Main.java
public static String getHmsTime() { SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss"); return format.format(new Date()); }
From source file:Main.java
public static String firstDayOfMonth() { Calendar c = Calendar.getInstance(); c.set(Calendar.DAY_OF_MONTH, 1); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); return df.format(c.getTime()); }
From source file:Main.java
/** * /*from w w w . ja v a 2 s.c o m*/ * @param pattern * @param seconds * @return */ public static String getTimeStr(String pattern, int seconds) { SimpleDateFormat sdf = new SimpleDateFormat(pattern); return sdf.format(new Date(seconds * 1000L)); }
From source file:Main.java
public static String GetDateString(long timestamp) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); return format.format(new Date(timestamp)); }
From source file:Main.java
public static String yesterday() { Calendar c = Calendar.getInstance(); c.add(Calendar.DATE, -1);/* www . j a v a 2 s . c om*/ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); return df.format(c.getTime()); }