List of usage examples for java.text SimpleDateFormat applyPattern
public void applyPattern(String pattern)
From source file:Main.java
@SuppressLint("SimpleDateFormat") public static long parse_iso_time_string_to_long(String iso_time_string) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyy-MM-dd'T'HH:mm:ssZ"); return sdf.parse(iso_time_string).getTime(); }
From source file:Main.java
@SuppressLint("SimpleDateFormat") public static String time_string(long time_seconds) { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("HH:mm"); return sdf.format(new Date(time_seconds * 1000)); }
From source file:Main.java
public static String getTodayDate() { TimeZone currZone = TimeZone.getTimeZone("Asia/Singapore"); Calendar myCal = Calendar.getInstance(currZone, new Locale("en")); SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyy-MM-dd"); return (sdf.format(myCal.getTime())); }
From source file:Main.java
public static String convertLongToString(long time, String format) { String myDate = null;/* w w w. j a va2 s .c om*/ SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern(format); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(time); Date date = calendar.getTime(); myDate = sdf.format(date); return myDate; }
From source file:Main.java
private static String createDate(Date date, String defaultFormat, Boolean utc) { SimpleDateFormat gmtFormat = new SimpleDateFormat(); gmtFormat.applyPattern(defaultFormat); TimeZone gmtTime = (utc) ? TimeZone.getTimeZone("GMT") : TimeZone.getDefault(); gmtFormat.setTimeZone(gmtTime);/* ww w . j a v a 2 s . co m*/ return gmtFormat.format(date); }
From source file:Main.java
public static String formatRFC3339UTC(Date date) { SimpleDateFormat format = RFC3339Formatter.get(); format.applyPattern(RFC3339UTC); return format.format(date); }
From source file:Main.java
/** * Encodes a DateTime./* w w w . j a va 2 s . c om*/ * * @param javaDate * a date * @return a String */ public static String encodeDateTime(Date javaDate) { final SimpleDateFormat df = new SimpleDateFormat(); df.applyPattern("yyyy-MM-dd'T'hh:mm:ss"); return df.format(javaDate); }
From source file:Main.java
/** * Encodes a date./*from w ww.j ava 2 s . c o m*/ * * @param javaDate * a Date * @return a String */ public static String encodeDate(Date javaDate) { final SimpleDateFormat df = new SimpleDateFormat(); df.applyPattern("yyyy-MM-dd"); return df.format(javaDate); }
From source file:Main.java
public static String formatRFC3339Local(Date date) { SimpleDateFormat format = RFC3339Formatter.get(); format.applyPattern(RFC3339LOCAL); String result = format.format(date); format.applyPattern(RFC3339UTC);/*from w ww. j a va2 s. com*/ return result; }
From source file:Main.java
/** * templete: Date -> FORMAT_STR// w ww . j a va 2 s.c om * * @param date * @param format * @return */ public static String date2str(Date date, String format) { if (date == null) { return null; } SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern(format); return sdf.format(date); }