/** * Get current date and time as a timestamp. * @return urrent date and time as a timestamp. */ public static String getTimestamp() { // Use GMT timezone //timestampFormat.setTimeZone(TimeZone.getTimeZone("GMT")); timestampFormat.setTimeZone(TimeZone.getDefault()); // Return timestamp return timestampFormat.format(new Date()); }
/** * Get current date for default time zone. * @return current date for default time zone. */ public static String getDate() { // Use GMT timezone dateFormat.setTimeZone(TimeZone.getDefault()); // Return date return dateFormat.format(new Date()); }
/** * Get the given date and time as a timestamp. * @param date: a date object. * @return the given date and time as a timestamp. */ public static String getTimestamp(Date date) { timestampFormat.setTimeZone(TimeZone.getDefault()); return timestampFormat.format(date); } }
private static DateFormat loadNumericDurationFormat( ICUResourceBundle r, String type) { r = r.getWithFallback(String.format("durationUnits/%s", type)); // We replace 'h' with 'H' because 'h' does not make sense in the context of durations. DateFormat result = new SimpleDateFormat(r.getString().replace("h", "H")); result.setTimeZone(TimeZone.GMT_ZONE); return result; }
@Override public String formatDate(String locale, Date date, String skeleton, String timezone) { ULocale closestLocale = localeService.getClosestULocale(locale); DateFormat formatter = DateFormat.getPatternInstance(skeleton, closestLocale); if (StringUtils.isNotEmpty(timezone)) { formatter.setTimeZone(TimeZone.getTimeZone(timezone)); } return formatter.format(date); }
@Override public Date parseDate(String locale, String value, String skeleton, String timezone) throws ParseException { ULocale closestLocale = findClosestULocale(locale); DateFormat formatter = DateFormat.getPatternInstance(skeleton, closestLocale); if (StringUtils.isNotEmpty(timezone)) { formatter.setTimeZone(TimeZone.getTimeZone(timezone)); } return formatter.parse(value); }
@Override public Date parseDate(String locale, String value, String skeleton, String timezone) throws ParseException { ULocale closestLocale = localeService.getClosestULocale(locale); DateFormat formatter = DateFormat.getPatternInstance(skeleton, closestLocale); if (StringUtils.isNotEmpty(timezone)) { formatter.setTimeZone(TimeZone.getTimeZone(timezone)); } return formatter.parse(value); }
@Override public String formatDate(String locale, Date date, String skeleton, String timezone) { ULocale closestLocale = findClosestULocale(locale); DateFormat formatter = DateFormat.getPatternInstance(skeleton, closestLocale); if (StringUtils.isNotEmpty(timezone)) { formatter.setTimeZone(TimeZone.getTimeZone(timezone)); } return formatter.format(date); }
format.setTimeZone(TimeZone.getTimeZone(timeZoneId)); return format.format(new Date(timeMillis));
result.setTimeZone(getTimeZone()); } else { result = guessDateFormat(dateStyle, timeStyle);