List of usage examples for java.text DateFormat setTimeZone
public void setTimeZone(TimeZone zone)
From source file:org.projectforge.calendar.ICal4JUtils.java
public static Date parseISODateString(final String isoDateString) { if (StringUtils.isBlank(isoDateString) == true) { return null; }//w w w.j a va2s. com String pattern; if (isoDateString.indexOf(':') > 0) { pattern = DateFormats.ISO_TIMESTAMP_SECONDS; } else { pattern = DateFormats.ISO_DATE; } final DateFormat df = new SimpleDateFormat(pattern); df.setTimeZone(DateHelper.UTC); try { return df.parse(isoDateString); } catch (final ParseException ex) { log.error("Can't parse ISO date ('" + pattern + "': " + ex.getMessage(), ex); return null; } }
From source file:com.taobao.adfs.database.tdhsocket.client.util.ConvertUtil.java
public static Long getTimeFromString(String stringVal, @Nullable Calendar cal) throws SQLException { if (stringVal == null) { return null; }//ww w. j a va2 s .c o m String val = stringVal.trim(); if (val.length() == 0) { return null; } if (val.equals("0") || val.equals("0000-00-00") || val.equals("0000-00-00 00:00:00") || val.equals("00000000000000") || val.equals("0")) { Calendar calendar = null; if (cal != null) { calendar = Calendar.getInstance(cal.getTimeZone()); } else { calendar = Calendar.getInstance(); } calendar.set(Calendar.YEAR, 1); calendar.set(Calendar.MONTH, 0); calendar.set(Calendar.DAY_OF_MONTH, 1); return calendar.getTimeInMillis(); } DateFormat dateFormat = DateFormat.getDateTimeInstance(); if (cal != null) { TimeZone timeZone = cal.getTimeZone(); dateFormat.setTimeZone(timeZone); } try { return dateFormat.parse(val).getTime(); } catch (ParseException e) { throw new SQLException("Parse date failure:" + val); } }
From source file:org.projectforge.calendar.ICal4JUtils.java
public static String asISODateString(final Date date, final java.util.TimeZone timeZone) { if (date == null) { return null; }/*from w ww . j a v a2 s . co m*/ final DateFormat df = new SimpleDateFormat(DateFormats.ISO_DATE); df.setTimeZone(timeZone); return df.format(date); }
From source file:org.nuxeo.ecm.platform.web.common.requestcontroller.filter.NuxeoRequestControllerFilter.java
private static DateFormat httpExpiresDateFormat() { // formatted http Expires: Thu, 01 Dec 1994 16:00:00 GMT DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); df.setTimeZone(TimeZone.getTimeZone("GMT")); return df;/*from w w w. ja va2 s. c om*/ }
From source file:org.projectforge.calendar.ICal4JUtils.java
public static String asISODateTimeString(final Date date) { if (date == null) { return null; }//from w w w . j a v a2s. c o m final DateFormat df = new SimpleDateFormat(DateFormats.ISO_TIMESTAMP_SECONDS); df.setTimeZone(DateHelper.UTC); return df.format(date); }
From source file:com.mercandalli.android.apps.files.main.Config.java
public static String getUserToken() { final DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US); df.setTimeZone(TimeZone.getTimeZone("gmt")); final String currentDate = df.format(new Date()); String log = ENUM_String.STRING_USER_USERNAME.value; String pass = HashUtils.sha1(HashUtils.sha1(ENUM_String.STRING_USER_PASSWORD.value) + currentDate); String authentication = String.format("%s:%s", log, pass); return Base64.encodeBytes(authentication.getBytes()); }
From source file:com.google.samples.apps.iosched.util.TimeUtils.java
public static String formatShortTime(Context context, Date time) { // Android DateFormatter will honor the user's current settings. DateFormat format = android.text.format.DateFormat.getTimeFormat(context); // Override with Timezone based on settings since users can override their phone's timezone // with Pacific time zones. TimeZone tz = SettingsUtils.getDisplayTimeZone(context); if (tz != null) { format.setTimeZone(tz); }//from w w w . j a v a2 s. c om return format.format(time); }
From source file:org.projectforge.framework.calendar.ICal4JUtils.java
/** * Format is '20130327T090000'/*from w w w . j a v a2s . com*/ * * @param dateString * @param timeZone * @return */ public static Date parseICalDateString(final String dateString, final java.util.TimeZone timeZone) { if (StringUtils.isBlank(dateString) == true) { return null; } String pattern; java.util.TimeZone tz = timeZone; if (dateString.indexOf('T') > 0) { pattern = ICAL_DATETIME_FORMAT; } else { pattern = ICAL_DATE_FORMAT; tz = DateHelper.UTC; } final DateFormat df = new SimpleDateFormat(pattern); df.setTimeZone(tz); try { return df.parse(dateString); } catch (final ParseException ex) { log.error("Can't parse ical date ('" + pattern + "': " + ex.getMessage(), ex); return null; } }
From source file:org.apache.falcon.util.DateUtil.java
private static DateFormat getISO8601DateFormat(TimeZone tz, String mask) { DateFormat dateFormat = new SimpleDateFormat(mask); // Stricter parsing to prevent dates such as 2011-12-50T01:00Z (December 50th) from matching dateFormat.setLenient(false);/*from www . j a va 2s. c om*/ dateFormat.setTimeZone(tz); return dateFormat; }
From source file:com.easou.common.util.CommonUtils.java
public static String formatForUtcTime(final Date date) { final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); return dateFormat.format(date); }