private DateFormat newDateFormat() { SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.US); dateFormat.setTimeZone(GMT); return dateFormat; }
private long parseDateHeader(String name, String value) { for (String dateFormat : DATE_FORMATS) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat, Locale.US); simpleDateFormat.setTimeZone(GMT); try { return simpleDateFormat.parse(value).getTime(); } catch (ParseException ex) { // ignore } } throw new IllegalArgumentException("Cannot parse date value '" + value + "' for '" + name + "' header"); }
public String getCurTime() { String fromTimeZone = "GMT+8"; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); format.setTimeZone(TimeZone.getTimeZone(fromTimeZone)); String chinaDate = format.format(date); return chinaDate; }
public static String dateToString(Date date) { if (date != null) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_PATTERN); simpleDateFormat.setTimeZone(UTC); return simpleDateFormat.format(date); } return ""; } }
/** * Generate a file name which represent a specific date. */ @Override public String generateFileName(int logLevel, long timestamp) { SimpleDateFormat sdf = mLocalDateFormat.get(); sdf.setTimeZone(TimeZone.getDefault()); return sdf.format(new Date(timestamp)); } }
private SimpleDateFormat createSimpleDateFormat() { SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); fmt.setTimeZone(TimeZone.getTimeZone("GMT+8:00")); return fmt; } }
public final String formatUTCTZ(Date date) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return sdf.format(date); }
private long parseDateValue(@Nullable String headerValue) { if (headerValue == null) { // No header value sent at all return -1; } if (headerValue.length() >= 3) { // Short "0" or "-1" like values are never valid HTTP date headers... // Let's only bother with SimpleDateFormat parsing for long enough values. for (String dateFormat : DATE_FORMATS) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat, Locale.US); simpleDateFormat.setTimeZone(GMT); try { return simpleDateFormat.parse(headerValue).getTime(); } catch (ParseException ex) { // ignore } } } return -1; }
public static String dateToString(Date date) { if (date != null) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_PATTERN); simpleDateFormat.setTimeZone(UTC); return simpleDateFormat.format(date); } return ""; } }
@Override protected DateFormat initialValue() { SimpleDateFormat format = new SimpleDateFormat(ISO_8601_PATTERN); format.setTimeZone(TimeZone.getTimeZone("UTC")); return format; } };
private RFC1123() { format = new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss Z", Locale.US ); format.setTimeZone( GMT ); }
/** * @param timeInMilliSeconds - The time in milliseconds * @param format - A format that can be used by {@link SimpleDateFormat} * @return - A formatted string representation of the time in UTC/GMT timezone. */ public static String timeInUTC(long timeInMilliSeconds, String format) { SimpleDateFormat sdf = new SimpleDateFormat(format); TimeZone utc = TimeZone.getTimeZone("UTC"); sdf.setTimeZone(utc); return sdf.format(timeInMilliSeconds); } }
public static long parseGMTToMillis(String gmtTime) throws ParseException { if (TextUtils.isEmpty(gmtTime)) return 0; SimpleDateFormat formatter = new SimpleDateFormat(FORMAT_HTTP_DATA, Locale.US); formatter.setTimeZone(GMT_TIME_ZONE); Date date = formatter.parse(gmtTime); return date.getTime(); }
String getStartDateTime() { if (startDateTime == null) { SimpleDateFormat format = new SimpleDateFormat( "EEE, d MMM yyyy HH:mm:ss z", new Locale("en", "")); format.setTimeZone(DateTimeUtils.UTC); startDateTime = format.format(System.currentTimeMillis()); } return startDateTime; }
@Override protected DateFormat initialValue() { SimpleDateFormat format = new SimpleDateFormat(ISO_8601_MILLIS_PATTERN); format.setTimeZone(TimeZone.getTimeZone("UTC")); return format; } };
public StoreFiles( DatabaseLayout databaseLayout ) { this.databaseLayout = databaseLayout; TimeZone tz = TimeZone.getDefault(); dateFormat = new SimpleDateFormat( FORMAT_DATE_ISO ); dateFormat.setTimeZone( tz ); }
public static String formatMillisToGMT(long milliseconds) { Date date = new Date(milliseconds); SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FORMAT_HTTP_DATA, Locale.US); simpleDateFormat.setTimeZone(GMT_TIME_ZONE); return simpleDateFormat.format(date); }
/** * Parsing the TimeZone of time in milliseconds. * * @param gmtTime GRM Time, Format such as: {@value #FORMAT_HTTP_DATA}. * @return The number of milliseconds from 1970.1.1. * @throws ParseException if an error occurs during parsing. */ public static long parseGMTToMillis(String gmtTime) throws ParseException { SimpleDateFormat formatter = new SimpleDateFormat(FORMAT_HTTP_DATA, Locale.US); formatter.setTimeZone(GMT_TIME_ZONE); Date date = formatter.parse(gmtTime); return date.getTime(); }
public static String dateToString(Date date) { if (date != null) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_PATTERN_FOR_V3); simpleDateFormat.setTimeZone(UTC); return simpleDateFormat.format(date); } return ""; } }
@Before public void setup() throws URISyntaxException { this.currentDate = Instant.now().truncatedTo(ChronoUnit.SECONDS); this.dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); this.dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); }