/** * Returns the given timestamp as String formatted in a localized pattern.<p> * * @param locale the locale for the time format * @param messages the messages that contain the time format definitions * @param timestamp the time to format * * @return the given timestamp as String formatted in a localized pattern */ public static String getCalendarLocalizedTime(Locale locale, CmsMessages messages, long timestamp) { // get the current date & time TimeZone zone = TimeZone.getDefault(); GregorianCalendar cal = new GregorianCalendar(zone, locale); cal.setTimeInMillis(timestamp); // format it nicely according to the localized pattern DateFormat df = new SimpleDateFormat( CmsCalendarWidget.getCalendarJavaDateFormat(messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_DATE_FORMAT_0) + " " + messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_TIME_FORMAT_0))); return df.format(cal.getTime()); }
/** * Returns the given timestamp as String formatted in a localized pattern.<p> * * @param locale the locale for the time format * @param messages the messages that contain the time format definitions * @param timestamp the time to format * * @return the given timestamp as String formatted in a localized pattern */ public static String getCalendarLocalizedTime(Locale locale, CmsMessages messages, long timestamp) { // get the current date & time TimeZone zone = TimeZone.getDefault(); GregorianCalendar cal = new GregorianCalendar(zone, locale); cal.setTimeInMillis(timestamp); // format it nicely according to the localized pattern DateFormat df = new SimpleDateFormat( CmsCalendarWidget.getCalendarJavaDateFormat( messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_DATE_FORMAT_0) + " " + messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_TIME_FORMAT_0))); return df.format(cal.getTime()); }
/** * Creates the time in milliseconds from the given parameter.<p> * * @param messages the messages that contain the time format definitions * @param dateString the String representation of the date * @param useTime true if the time should be parsed, too, otherwise false * * @return the time in milliseconds * * @throws ParseException if something goes wrong */ public static long getCalendarDate(CmsMessages messages, String dateString, boolean useTime) throws ParseException { long dateLong = 0; // substitute some chars because calendar syntax != DateFormat syntax String dateFormat = messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_DATE_FORMAT_0); if (useTime) { dateFormat += " " + messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_TIME_FORMAT_0); } dateFormat = CmsCalendarWidget.getCalendarJavaDateFormat(dateFormat); SimpleDateFormat df = new SimpleDateFormat(dateFormat); dateLong = df.parse(dateString).getTime(); return dateLong; }
/** * Creates the time in milliseconds from the given parameter.<p> * * @param messages the messages that contain the time format definitions * @param dateString the String representation of the date * @param useTime true if the time should be parsed, too, otherwise false * * @return the time in milliseconds * * @throws ParseException if something goes wrong */ public static long getCalendarDate(CmsMessages messages, String dateString, boolean useTime) throws ParseException { long dateLong = 0; // substitute some chars because calendar syntax != DateFormat syntax String dateFormat = messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_DATE_FORMAT_0); if (useTime) { dateFormat += " " + messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_TIME_FORMAT_0); } dateFormat = CmsCalendarWidget.getCalendarJavaDateFormat(dateFormat); SimpleDateFormat df = new SimpleDateFormat(dateFormat); dateLong = df.parse(dateString).getTime(); return dateLong; }