List of usage examples for java.text DateFormat setTimeZone
public void setTimeZone(TimeZone zone)
From source file:org.mxupdate.update.util.StringUtil_mxJPO.java
/** * Formats given installation date to the related string representation in * MX. The convert is done in time zone {@link #TIMEZONE} so that always * the same time zone is used (e.g. summer and winter time...). *//from www .java 2 s . c o m * @param _paramCache parameter cache * @param _date installed date to convert to a string * @return string representation of the date in time zone {@link #TIMEZONE} * @see #PARAM_INSTALLEDDATEFORMAT */ public static String formatInstalledDate(final ParameterCache_mxJPO _paramCache, final Date _date) { final DateFormat fileFormat = new SimpleDateFormat( _paramCache.getValueString(StringUtil_mxJPO.PARAM_INSTALLEDDATEFORMAT)); fileFormat.setTimeZone(StringUtil_mxJPO.TIMEZONE); return fileFormat.format(_date); }
From source file:org.mxupdate.update.util.StringUtil_mxJPO.java
/** * Parses given string with date in time zone {@link #TIMEZONE} and returns * related date.// ww w. j a v a 2 s .c o m * * @param _paramCache parameter cache * @param _date string with the installed date in time zone * {@link #TIMEZONE} * @return parsed date instance * @throws ParseException if date string could not be parsed * @see #PARAM_INSTALLEDDATEFORMAT */ public static Date parseInstalledDate(final ParameterCache_mxJPO _paramCache, final String _date) throws ParseException { final DateFormat fileFormat = new SimpleDateFormat( _paramCache.getValueString(StringUtil_mxJPO.PARAM_INSTALLEDDATEFORMAT)); fileFormat.setTimeZone(StringUtil_mxJPO.TIMEZONE); return fileFormat.parse(_date); }
From source file:org.kalypso.ogc.sensor.diagview.jfreechart.DateAxis.java
/** * Special tick units for kalypso/*from w ww . j av a2s .c om*/ */ public static TickUnitSource createStandardDateTickUnits(final TimeZone zone) { if (zone == null) throw new IllegalArgumentException("Null 'zone' argument."); //$NON-NLS-1$ final TickUnits units = new TickUnits(); // date formatters // DateFormat f1 = new SimpleDateFormat("HH:mm:ss.SSS"); // DateFormat f2 = new SimpleDateFormat("HH:mm:ss"); // DateFormat f3 = new SimpleDateFormat("HH:mm"); // DateFormat f4 = new SimpleDateFormat("d-MMM, HH:mm"); // DateFormat f5 = new SimpleDateFormat("d-MMM"); // DateFormat f6 = new SimpleDateFormat("MMM-yyyy"); // DateFormat f7 = new SimpleDateFormat("yyyy"); final DateFormat f1 = new SimpleDateFormat("dd.MM HH:mm:ss.SSS"); //$NON-NLS-1$ final DateFormat f2 = new SimpleDateFormat("dd.MM HH:mm:ss"); //$NON-NLS-1$ final DateFormat f3 = new SimpleDateFormat("dd.MM HH:mm"); //$NON-NLS-1$ final DateFormat f4 = new SimpleDateFormat("dd.MM HH:mm"); //$NON-NLS-1$ final DateFormat f5 = new SimpleDateFormat("dd.MM"); //$NON-NLS-1$ final DateFormat f6 = new SimpleDateFormat("dd.MM.yy"); //$NON-NLS-1$ final DateFormat f7 = new SimpleDateFormat("yyyy"); //$NON-NLS-1$ f1.setTimeZone(zone); f2.setTimeZone(zone); f3.setTimeZone(zone); f4.setTimeZone(zone); f5.setTimeZone(zone); f6.setTimeZone(zone); f7.setTimeZone(zone); // milliseconds units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 1, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 5, DateTickUnit.MILLISECOND, 1, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 10, DateTickUnit.MILLISECOND, 1, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 25, DateTickUnit.MILLISECOND, 5, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 50, DateTickUnit.MILLISECOND, 10, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 100, DateTickUnit.MILLISECOND, 10, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 250, DateTickUnit.MILLISECOND, 10, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 500, DateTickUnit.MILLISECOND, 50, f1)); // seconds units.add(new DateTickUnit(DateTickUnit.SECOND, 1, DateTickUnit.MILLISECOND, 50, f2)); units.add(new DateTickUnit(DateTickUnit.SECOND, 5, DateTickUnit.SECOND, 1, f2)); units.add(new DateTickUnit(DateTickUnit.SECOND, 10, DateTickUnit.SECOND, 1, f2)); units.add(new DateTickUnit(DateTickUnit.SECOND, 30, DateTickUnit.SECOND, 5, f2)); // minutes units.add(new DateTickUnit(DateTickUnit.MINUTE, 1, DateTickUnit.SECOND, 5, f3)); units.add(new DateTickUnit(DateTickUnit.MINUTE, 2, DateTickUnit.SECOND, 10, f3)); units.add(new DateTickUnit(DateTickUnit.MINUTE, 5, DateTickUnit.MINUTE, 1, f3)); units.add(new DateTickUnit(DateTickUnit.MINUTE, 10, DateTickUnit.MINUTE, 1, f3)); units.add(new DateTickUnit(DateTickUnit.MINUTE, 15, DateTickUnit.MINUTE, 5, f3)); units.add(new DateTickUnit(DateTickUnit.MINUTE, 20, DateTickUnit.MINUTE, 5, f3)); units.add(new DateTickUnit(DateTickUnit.MINUTE, 30, DateTickUnit.MINUTE, 5, f3)); // hours units.add(new DateTickUnit(DateTickUnit.HOUR, 1, DateTickUnit.MINUTE, 5, f3)); units.add(new DateTickUnit(DateTickUnit.HOUR, 2, DateTickUnit.MINUTE, 10, f3)); units.add(new DateTickUnit(DateTickUnit.HOUR, 4, DateTickUnit.MINUTE, 30, f3)); units.add(new DateTickUnit(DateTickUnit.HOUR, 6, DateTickUnit.HOUR, 1, f3)); units.add(new DateTickUnit(DateTickUnit.HOUR, 12, DateTickUnit.HOUR, 1, f4)); // days units.add(new DateTickUnit(DateTickUnit.DAY, 1, DateTickUnit.HOUR, 1, f5)); units.add(new DateTickUnit(DateTickUnit.DAY, 2, DateTickUnit.HOUR, 1, f5)); units.add(new DateTickUnit(DateTickUnit.DAY, 3, DateTickUnit.HOUR, 1, f5)); units.add(new DateTickUnit(DateTickUnit.DAY, 4, DateTickUnit.HOUR, 1, f5)); units.add(new DateTickUnit(DateTickUnit.DAY, 5, DateTickUnit.HOUR, 1, f5)); units.add(new DateTickUnit(DateTickUnit.DAY, 6, DateTickUnit.HOUR, 1, f5)); units.add(new DateTickUnit(DateTickUnit.DAY, 7, DateTickUnit.DAY, 1, f5)); units.add(new DateTickUnit(DateTickUnit.DAY, 10, DateTickUnit.DAY, 1, f5)); units.add(new DateTickUnit(DateTickUnit.DAY, 15, DateTickUnit.DAY, 1, f5)); // months units.add(new DateTickUnit(DateTickUnit.MONTH, 1, DateTickUnit.DAY, 1, f6)); units.add(new DateTickUnit(DateTickUnit.MONTH, 2, DateTickUnit.DAY, 1, f6)); units.add(new DateTickUnit(DateTickUnit.MONTH, 3, DateTickUnit.MONTH, 1, f6)); units.add(new DateTickUnit(DateTickUnit.MONTH, 4, DateTickUnit.MONTH, 1, f6)); units.add(new DateTickUnit(DateTickUnit.MONTH, 6, DateTickUnit.MONTH, 1, f6)); // years units.add(new DateTickUnit(DateTickUnit.YEAR, 1, DateTickUnit.MONTH, 1, f7)); units.add(new DateTickUnit(DateTickUnit.YEAR, 2, DateTickUnit.MONTH, 3, f7)); units.add(new DateTickUnit(DateTickUnit.YEAR, 5, DateTickUnit.YEAR, 1, f7)); units.add(new DateTickUnit(DateTickUnit.YEAR, 10, DateTickUnit.YEAR, 1, f7)); units.add(new DateTickUnit(DateTickUnit.YEAR, 25, DateTickUnit.YEAR, 5, f7)); units.add(new DateTickUnit(DateTickUnit.YEAR, 50, DateTickUnit.YEAR, 10, f7)); units.add(new DateTickUnit(DateTickUnit.YEAR, 100, DateTickUnit.YEAR, 20, f7)); return units; }
From source file:com.google.samples.apps.iosched.util.UIUtils.java
/** * Format and return the given session time and {@link Rooms} values using {@link * Config#CONFERENCE_TIMEZONE}./*from w ww. ja v a 2 s. c om*/ */ public static String formatSessionSubtitle(long intervalStart, long intervalEnd, String roomName, StringBuilder recycle, Context context, boolean shortFormat) { // Determine if the session is in the past long currentTimeMillis = TimeUtils.getCurrentTime(context); boolean conferenceEnded = currentTimeMillis > Config.CONFERENCE_END_MILLIS; boolean sessionEnded = currentTimeMillis > intervalEnd; if (sessionEnded && !conferenceEnded) { return context.getString(R.string.session_finished); } if (roomName == null) { roomName = context.getString(R.string.unknown_room); } if (shortFormat) { TimeZone timeZone = SettingsUtils.getDisplayTimeZone(context); Date intervalStartDate = new Date(intervalStart); SimpleDateFormat shortDateFormat = new SimpleDateFormat("MMM dd"); DateFormat shortTimeFormat = DateFormat.getTimeInstance(DateFormat.SHORT); shortDateFormat.setTimeZone(timeZone); shortTimeFormat.setTimeZone(timeZone); return shortDateFormat.format(intervalStartDate) + " " + shortTimeFormat.format(intervalStartDate); } else { String timeInterval = formatIntervalTimeString(intervalStart, intervalEnd, recycle, context); return context.getString(R.string.session_subtitle, timeInterval, roomName); } }
From source file:de.fu_berlin.inf.dpp.feedback.SessionStatistic.java
private static String toISO8601UTCTimeFormat(Date date) { TimeZone timeZone = TimeZone.getTimeZone("UTC"); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); dateFormat.setTimeZone(timeZone); return dateFormat.format(date); }
From source file:com.stfalcon.contentmanager.ContentManager.java
/** * Converts a Date object to a string representation. * * @param date//from ww w . j ava 2 s. c o m * @return date as String */ public static String dateToString(Date date) { if (date == null) { return null; } else { DateFormat df = new SimpleDateFormat(dateFormat); df.setTimeZone(utc); return df.format(date); } }
From source file:com.stfalcon.contentmanager.ContentManager.java
/** * Converts a string representation of a date to its respective Date object. * * @param dateAsString//from w w w. j a v a 2 s . co m * @return Date */ public static Date stringToDate(String dateAsString) { try { DateFormat df = new SimpleDateFormat(dateFormat); df.setTimeZone(utc); return df.parse(dateAsString); } catch (ParseException e) { return null; } catch (NullPointerException e) { return null; } }
From source file:Main.java
/** * For some reason, can't find this utility method in the java framework. * /*from w w w . j av a 2 s . com*/ * @param sDateTime * an xsd:dateTime string * @return an equivalent java.util.Date * @throws ParseException */ public static Date parseXsdDateTime(String sDateTime) throws ParseException { final DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); int iDotPosition = NORMAL_IDOT_POSITION; if (sDateTime.charAt(0) == '-') { iDotPosition = IDOT_POSITION_IFNEG; } Date result; if (sDateTime.length() <= iDotPosition) { return format.parse(sDateTime + "Z"); } String millis = null; char c = sDateTime.charAt(iDotPosition); if (c == '.') { // if datetime has milliseconds, separate them int eoms = iDotPosition + 1; while (Character.isDigit(sDateTime.charAt(eoms))) { eoms += 1; } millis = sDateTime.substring(iDotPosition, eoms); sDateTime = sDateTime.substring(0, iDotPosition) + sDateTime.substring(eoms); c = sDateTime.charAt(iDotPosition); } if (c == '+' || c == '-') { format.setTimeZone(TimeZone.getTimeZone("GMT" + sDateTime.substring(iDotPosition))); sDateTime = sDateTime.substring(0, iDotPosition) + "Z"; } else if (c != 'Z') { throw new ParseException("Illegal timezone specification.", iDotPosition); } result = format.parse(sDateTime); if (millis != null) { result.setTime(result.getTime() + Math.round(Float.parseFloat(millis) * ONE_SEC_IN_MILLISECS)); } result = offsetDateFromGMT(result); return result; }
From source file:org.kalypso.kalypsomodel1d2d.conv.results.ResultMeta1d2dHelper.java
public static void addToResultDB(final IStepResultMeta stepResultMeta, final Date stepDate, final File outputDir) { // TODO: retrieve time zone from central plugin preferences final DateFormat dateFormatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG); dateFormatter.setTimeZone(KalypsoCorePlugin.getDefault().getTimeZone()); if (ResultManager.STEADY_DATE.equals(stepDate)) { stepResultMeta.setName(//from w ww .j a v a 2 s. c o m Messages.getString("org.kalypso.kalypsomodel1d2d.conv.results.ResultMeta1d2dHelper.93")); //$NON-NLS-1$ stepResultMeta.setDescription( Messages.getString("org.kalypso.kalypsomodel1d2d.conv.results.ResultMeta1d2dHelper.94")); //$NON-NLS-1$ stepResultMeta.setStepType(IStepResultMeta.STEPTYPE.steady); stepResultMeta.setStepTime(null); } else if (ResultManager.MAXI_DATE.equals(stepDate)) { stepResultMeta.setName( Messages.getString("org.kalypso.kalypsomodel1d2d.conv.results.ResultMeta1d2dHelper.95")); //$NON-NLS-1$ stepResultMeta.setDescription( Messages.getString("org.kalypso.kalypsomodel1d2d.conv.results.ResultMeta1d2dHelper.96")); //$NON-NLS-1$ stepResultMeta.setStepType(IStepResultMeta.STEPTYPE.maximum); stepResultMeta.setStepTime(null); } else { // TODO: check for right time zone final String dateString = dateFormatter.format(stepDate); stepResultMeta.setName(Messages .getString("org.kalypso.kalypsomodel1d2d.conv.results.ResultMeta1d2dHelper.97", dateString)); //$NON-NLS-1$ stepResultMeta.setDescription( Messages.getString("org.kalypso.kalypsomodel1d2d.conv.results.ResultMeta1d2dHelper.98") //$NON-NLS-1$ + dateString); stepResultMeta.setStepType(IStepResultMeta.STEPTYPE.unsteady); stepResultMeta.setStepTime(stepDate); } stepResultMeta.setPath(new Path(outputDir.getName())); }
From source file:iddb.web.viewbean.NoticeViewBean.java
@Override public String toString() { StringBuilder s = new StringBuilder(); DateFormat format = new SimpleDateFormat("dd/MM/yyyy"); format.setTimeZone(TimeZone.getTimeZone("GMT-3")); s.append(getReason()).append(". "); s.append("Agregado el ").append(format.format(this.getCreated())); if (StringUtils.isNotEmpty(this.getAdmin())) { s.append(" por ").append(getAdmin()); }// w w w .j av a 2 s.c o m return s.toString(); }