List of usage examples for java.text SimpleDateFormat setTimeZone
public void setTimeZone(TimeZone zone)
From source file:org.opendatakit.common.utils.WebUtils.java
/** * Return the RFC1123 string representation of a date. * //from w w w . j ava 2 s .c o m * @param d * @return */ public static final String rfc1123Date(Date d) { if (d == null) return null; // SDF is not thread-safe SimpleDateFormat asGMTrfc1123 = new SimpleDateFormat(PATTERN_RFC1123); // with // time // zone asGMTrfc1123.setTimeZone(TimeZone.getTimeZone("GMT")); return asGMTrfc1123.format(d); }
From source file:com.icloud.framework.http.heritrix.ArchiveUtils.java
private static ThreadLocal<SimpleDateFormat> threadLocalDateFormat(final String pattern) { ThreadLocal<SimpleDateFormat> tl = new ThreadLocal<SimpleDateFormat>() { protected SimpleDateFormat initialValue() { SimpleDateFormat df = new SimpleDateFormat(pattern); df.setTimeZone(TimeZone.getTimeZone("GMT")); return df; }/*from w w w . j av a2 s . c o m*/ }; return tl; }
From source file:com.funambol.exchange.util.DateTools.java
/** * Make a webdav tag date from a date/* ww w . jav a2s. c om*/ * * @param date * date * @return webdav tag date */ public static String dateToWebDavTag(Date date) { SimpleDateFormat formatter; String webDavDate; if (date != null) { formatter = new SimpleDateFormat(DATE_FORMAT_WEBDAV); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); webDavDate = formatter.format(date); if (webDavDate.length() > 4) { String year = webDavDate.substring(0, 4); if (Integer.parseInt(year) > MAX_YEAR) { webDavDate = ""; } } } else { webDavDate = ""; } return webDavDate; }
From source file:com.funambol.exchange.util.DateTools.java
/** * Make a date from a webdav tag date to client date * /*from w ww. j a va 2s . c o m*/ * @param date * webdav tag content * @return a Date * @throws XmlParseException */ public static String toClientDate(Date date) throws XmlParseException { SimpleDateFormat formatter; try { if (date != null) { formatter = new SimpleDateFormat(DATETIME_FORMAT_CLIENT_UTC); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); return formatter.format(date); } else { return null; } } catch (Exception e) { throw new XmlParseException(e.toString()); } }
From source file:com.zimbra.qa.unittest.TestJaxb.java
private static long ymdStringToDate(String ymdString) { SimpleDateFormat formatter = new SimpleDateFormat(YMD_PATTERN, Locale.US); formatter.setTimeZone(GMT); Date date;//from ww w .j a va 2s . c o m try { date = formatter.parse(ymdString); return date.getTime(); } catch (ParseException e) { Assert.fail( String.format("Failed to convert string %s to long - exception %s", ymdString, e.getMessage())); } return 0; }
From source file:com.funambol.exchange.util.DateTools.java
public static Date pdiToGmtDate(String date) throws XmlParseException { SimpleDateFormat formatter; Date dt;/*from w w w .j a va 2 s . c o m*/ try { if (date != null) { formatter = new SimpleDateFormat(DATE_FORMAT_PDI); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); dt = formatter.parse(date); } else { dt = null; } } catch (ParseException e) { throw new XmlParseException(e.toString()); } return dt; }
From source file:org.opendatakit.briefcase.util.WebUtils.java
private static final Date parseDateSubset(String value, String[] parsePatterns, Locale l, TimeZone tz) { // borrowed from apache.commons.lang.DateUtils... Date d = null;/*w ww . jav a 2s . c om*/ SimpleDateFormat parser = null; ParsePosition pos = new ParsePosition(0); for (int i = 0; i < parsePatterns.length; i++) { if (i == 0) { if (l == null) { parser = new SimpleDateFormat(parsePatterns[0]); } else { parser = new SimpleDateFormat(parsePatterns[0], l); } } else { parser.applyPattern(parsePatterns[i]); } parser.setTimeZone(tz); // enforce UTC for formats without timezones pos.setIndex(0); d = parser.parse(value, pos); if (d != null && pos.getIndex() == value.length()) { return d; } } return d; }
From source file:com.funambol.exchange.util.DateTools.java
/** * <p>//from w w w .j a v a 2s. c o m * Convert a date in WebDav format ("yyyy-MM-dd'T'KK:mm:ss.fff'Z'") in day * format ("yyyy-MM-dd") * </p> * * @param date * @param timezone * @param isAStartDate * flag that tells if the input String represents a start date * @return the date in day format * @throws XmlParseException */ public static String convertWebDavDateToDay(String date, String timezone) throws XmlParseException { SimpleDateFormat formatter; Date dt; String funambolDate; if (date != null && date.length() > 0) { formatter = new SimpleDateFormat(DATE_FORMAT_WEBDAV); try { formatter.setTimeZone(TimeZone.getTimeZone("GMT")); dt = formatter.parse(date); long time = dt.getTime(); long offset = TimeZone.getTimeZone(timezone).getOffset(time); dt = new Date(time + offset); } catch (ParseException e) { throw new XmlParseException("Error converting date", e); } formatter.applyPattern(DateTools.ANNIVERSARY_FORMAT_PDI); funambolDate = formatter.format(dt); } else { funambolDate = null; } return funambolDate; }
From source file:org.kohsuke.github.GitHub.java
static Date parseDate(String timestamp) { if (timestamp == null) return null; for (String f : TIME_FORMATS) { try {//from ww w.ja v a 2 s . co m SimpleDateFormat df = new SimpleDateFormat(f); df.setTimeZone(TimeZone.getTimeZone("GMT")); return df.parse(timestamp); } catch (ParseException e) { // try next } } throw new IllegalStateException("Unable to parse the timestamp: " + timestamp); }
From source file:com.att.aro.core.util.Util.java
public static long parseForUTC(String creationTime) { long milli = 0; if (creationTime != null) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); Date date = null;/*w w w. ja v a 2 s .c o m*/ try { date = sdf.parse(creationTime); milli = date.getTime(); } catch (Exception e) { logger.error("Date parsing error :" + e.getMessage()); } } return milli; }