List of usage examples for java.text DateFormat format
public final String format(Date date)
From source file:it.marcoberri.mbmeteo.action.Commons.java
public static TreeMap<String, Date> getDistinctTime() { final Datastore ds = MongoConnectionHelper.ds; final List<Date> datesResult = ds.getDB().getCollection("Meteolog").distinct("time"); final TreeMap<String, Date> dates = new TreeMap<String, Date>(); final DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); for (Date d : datesResult) { try {/*from ww w.j av a2s .c o m*/ dates.put(df.format(d), d); } catch (Exception e) { continue; } } return dates; }
From source file:com.tascape.qa.th.Utils.java
public static String formatTime(long milliSinceEpoch, String format) { DateFormat formatter = new SimpleDateFormat(format); return formatter.format(new Date(milliSinceEpoch)); }
From source file:com.tascape.qa.th.Utils.java
public static String getCurrentTime(String format) { DateFormat formatter = new SimpleDateFormat(format); return formatter.format(new Date()); }
From source file:com.cisco.ca.cstg.pdi.utils.Util.java
public static String getCurrentDateTime() { Date date = new Date(); DateFormat df = new SimpleDateFormat("yyMMddhhmm"); return df.format(date.getTime()); }
From source file:com.fluidops.iwb.api.ValueResolver.java
/** * Convert a timestamp like 182843848 to a human-readable date. * //from w w w . ja v a 2 s . c o m * @param value * @return */ private static String resolveDateFromTimestamp(String value, long multiplyToMs) { Long t = Long.valueOf(value) * multiplyToMs; GregorianCalendar c = new GregorianCalendar(); c.setTimeInMillis(t); DateFormat df = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss"); return df.format(c.getTime()); }
From source file:DateFormatDemo.java
static public void showBothStyles(Locale currentLocale) { Date today;/*from w w w . jav a2s . c om*/ String result; DateFormat formatter; int[] styles = { DateFormat.DEFAULT, DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG, DateFormat.FULL }; System.out.println(); System.out.println("Locale: " + currentLocale.toString()); System.out.println(); today = new Date(); for (int k = 0; k < styles.length; k++) { formatter = DateFormat.getDateTimeInstance(styles[k], styles[k], currentLocale); result = formatter.format(today); System.out.println(result); } }
From source file:net.joinedminds.masserr.Functions.java
public static String formatDate(Date dateTime) { StaplerRequest request = Stapler.getCurrentRequest(); DateFormat format; if (request != null) { format = DateFormat.getDateInstance(DateFormat.MEDIUM, request.getLocale()); } else {/* ww w.java 2 s . c o m*/ format = DateFormat.getDateInstance(DateFormat.MEDIUM); } return format.format(dateTime); }
From source file:com.ushahidi.android.app.util.Util.java
/** * Format date into more readable format. * //from w ww.ja va 2s .c om * @param date - the date to be formatted. * @return String */ public static String formatDate(String dateFormat, String date, String toFormat) { String formatted = ""; DateFormat formatter = new SimpleDateFormat(dateFormat); try { Date dateStr = formatter.parse(date); formatted = formatter.format(dateStr); Date formatDate = formatter.parse(formatted); formatter = new SimpleDateFormat(toFormat); formatted = formatter.format(formatDate); } catch (ParseException e) { e.printStackTrace(); } return formatted; }
From source file:sk.lazyman.gizmo.util.GizmoUtils.java
public static String formatDate(Date date, String pattern) { if (date == null) { return null; }//from ww w. ja v a2 s. com DateFormat df = new SimpleDateFormat(pattern); return df.format(date); }
From source file:Dates.java
public static String dateTimeFormatForJSCalendar(Locale locale) { DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale); String datetime = df.format(create(1, 2, 1971, 15, 59, 0)); // d, m, y, hr, min, sec boolean always4InYear = "es".equals(locale.getLanguage()) || "pl".equals(locale.getLanguage()); String result = datetime./*w w w . j a va 2s. co m*/ // time part replaceAll("15", "%H"). // 24hr format replaceAll("03", "%I"). // 12hr format - double digit replaceAll("3", "%l"). // 12hr format - single digit replaceAll("59", "%M"). // minute replaceAll("PM", "%p"). // AM/PM - uppercase replaceAll("pm", "%P"). // am/pm - lowercase // date part replaceAll("01", "%d"). // day - double digit replaceAll("02", "%m"). // month - double digit replaceAll("1971", "%Y"). // year - 4 digit replaceAll("71", always4InYear ? "%Y" : "%y"). // year - 2 digit replaceAll("1", "%e"). // day - single digit replaceAll("2", "%m") // month - ??? seems only double digit is supported by calendar ; return result; }