List of usage examples for java.text DateFormat format
public final String format(Date date)
From source file:Main.java
/** * Converts Unix time to human readable format * @param milliseconds that have passed since 01/01/1970 * @return The human readable time for the users locale *///from w w w . j ava 2 s. co m public static String unixTimeToHumanReadable(long milliseconds) { Date date = new Date(milliseconds); DateFormat df = DateFormat.getDateTimeInstance(); return df.format(date); }
From source file:Main.java
public static String getTimeString(Date date) { if (date == null) { return ""; }/*from w w w .jav a2 s. c o m*/ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return dateFormat.format(date); }
From source file:Main.java
public static boolean isToDay(Date date) { DateFormat dateFormat = DateFormat.getDateInstance(); String format = dateFormat.format(new Date()); try {//from w ww .ja va 2 s . c om Date today = dateFormat.parse(format); return today.before(date); } catch (ParseException e) { e.printStackTrace(); } return true; }
From source file:Main.java
public static String getDateTime() { Date date = new Date(); DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time = format.format(date); return time;//from www.ja va 2 s . co m }
From source file:Main.java
/** * get date as string from date-object// w w w . ja v a 2 s. co m * * @param Date date - date-object * @return String - string representation of the date (yyyy/MM/dd) */ public static String getDate(Date date) { DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); return ((dateFormat.format(date)).split(" "))[0]; }
From source file:Main.java
public static String getYear_Second2() { java.util.Date date1 = new java.util.Date(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String timeStr2 = df.format(date1); return timeStr2; }
From source file:Main.java
public static String formatPublishedAt(String str) { // yyyy-MM-dd'T'HH:mm:ss.SSSZ try {/*from w w w . ja v a 2s.c om*/ DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); Date date = format.parse(str); DateFormat format2 = new SimpleDateFormat("yyyy/MM/dd"); return format2.format(date); } catch (ParseException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
/** * get time as string from date-object//from www . j a va2 s.c om * * @param Date date - date-object * @return String - string representation of the time (HH:mm:ss) */ public static String getTime(Date date) { DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); return ((dateFormat.format(date)).split(" "))[1]; }
From source file:Main.java
private static String getLogHeader() { DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss", Locale.US); return "[" + dateFormat.format(Calendar.getInstance().getTime()) + "] "; }
From source file:Main.java
public static String getStringDate(long timestamp, Context context) { Date date = new Date(timestamp); DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context); return dateFormat.format(date); }