public StoreFiles( DatabaseLayout databaseLayout ) { this.databaseLayout = databaseLayout; TimeZone tz = TimeZone.getDefault(); dateFormat = new SimpleDateFormat( FORMAT_DATE_ISO ); dateFormat.setTimeZone( tz ); }
/** * <p>Gets a formatter instance using the default pattern in the * default timezone and locale.</p> * * @return a date/time formatter */ public F getInstance() { return getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, TimeZone.getDefault(), Locale.getDefault()); }
@Config("hive.time-zone") public HiveClientConfig setTimeZone(String id) { this.timeZone = (id != null) ? id : TimeZone.getDefault().getID(); return this; }
TimeZone.getDefault().inDaylightTime( new Date() );
TimeZone timeZone = TimeZone.getTimeZone("UTC"); Calendar calendar = Calendar.getInstance(timeZone); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EE MMM dd HH:mm:ss zzz yyyy", Locale.US); simpleDateFormat.setTimeZone(timeZone); System.out.println("Time zone: " + timeZone.getID()); System.out.println("default time zone: " + TimeZone.getDefault().getID()); System.out.println(); System.out.println("UTC: " + simpleDateFormat.format(calendar.getTime())); System.out.println("Default: " + calendar.getTime());
SimpleDateFormat result = new SimpleDateFormat(pattern); return createDateFormat(pattern, TimeZone.getDefault()); return createDateFormat(ISO_FORMAT_WITH_TZ, TimeZone.getDefault()); final TimeZone defaultTZ = TimeZone.getDefault(); final int defaultOffset = defaultTZ.getOffset(nowInMillis) / MILLIS_IN_HOUR; final int userOffset = TimeZone.getTimeZone(System .getProperty("user.timezone")).getOffset(nowInMillis) / MILLIS_IN_HOUR; final Locale defaultLocale = Locale.getDefault(); System.out.println(" default.timezone.id = " + defaultTZ.getID()); System.out.println(" default.timezone-offset (hours) = " + defaultOffset); System.out.println(" default.locale = " public void setUp() throws Exception { now = new Date(); londonTimeZone = TimeZone.getTimeZone("GMT"); newYorkTimeZone = TimeZone.getTimeZone("GMT-5"); sydneyTimeZone = TimeZone.getTimeZone("GMT+10");
public static String dateAsIsoString(Date date) { TimeZone tz = TimeZone.getDefault(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); df.setTimeZone(tz); return df.format(date); }
private static void refreshTimezone() { try { TimeZone tz = TimeZone.getDefault(); deviceTimezoneAbbreviation = tz.getDisplayName( tz.inDaylightTime(new Date()), TimeZone.SHORT ); deviceTimeZoneName = tz.getID(); } catch (AssertionError e) { // Workaround for a bug in Android that can cause crashes on Android 8.0 and 8.1 } catch (Exception e) { } }
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { reader.moveDown(); long timeInMillis = Long.parseLong(reader.getValue()); reader.moveUp(); final String timeZone; if (reader.hasMoreChildren()) { reader.moveDown(); timeZone = reader.getValue(); reader.moveUp(); } else { // backward compatibility to XStream 1.1.2 and below timeZone = TimeZone.getDefault().getID(); } GregorianCalendar result = new GregorianCalendar(); result.setTimeZone(TimeZone.getTimeZone(timeZone)); result.setTime(new Date(timeInMillis)); // calendar.setTimeInMillis() not available under JDK 1.3 return result; }
public static String formatDateRange(long startMs, long endMs, int flags, String olsonId) { if ((flags & FORMAT_UTC) != 0) { olsonId = "UTC"; } TimeZone tz = (olsonId != null) ? TimeZone.getTimeZone(olsonId) : TimeZone.getDefault(); return formatDateRange(Locale.getDefault(), tz, startMs, endMs, flags); }
@Test @SuppressWarnings("deprecation") public void testBindInstantFromJavaUtilDate() { TimeZone defaultZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("GMT")); try { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("instant", new Date(109, 9, 31, 12, 0)); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertTrue(binder.getBindingResult().getFieldValue("instant").toString().startsWith("2009-10-31")); } finally { TimeZone.setDefault(defaultZone); } }
@Test public void testCheckDefaults() { final FastDateFormat format = FastDateFormat.getInstance(); final FastDateFormat medium = FastDateFormat.getDateTimeInstance(FastDateFormat.SHORT, FastDateFormat.SHORT); assertEquals(medium, format); final SimpleDateFormat sdf = new SimpleDateFormat(); assertEquals(sdf.toPattern(), format.getPattern()); assertEquals(Locale.getDefault(), format.getLocale()); assertEquals(TimeZone.getDefault(), format.getTimeZone()); }
@Before public void setUp() throws Exception { dateParser = new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH); dateTimeParser = new SimpleDateFormat("MMM dd, yyyy H:mm:ss.SSS", Locale.ENGLISH); date1 = dateTimeParser.parse("February 12, 2002 12:34:56.789"); date2 = dateTimeParser.parse("November 18, 2001 1:23:11.321"); defaultZone = TimeZone.getDefault(); zone = TimeZone.getTimeZone("MET"); try { TimeZone.setDefault(zone);
@JsonProperty public void setTimeZone(String zoneId) { this.timeZone = Strings.nullToEmpty(zoneId).equalsIgnoreCase("system") ? TimeZone.getDefault() : TimeZone.getTimeZone(zoneId); }
public ClientSession getClientSession() { return new ClientSession( parseServer(server), user, "presto-benchmark", Optional.empty(), ImmutableSet.of(), null, catalog, schema, null, TimeZone.getDefault().getID(), Locale.getDefault(), ImmutableMap.of(), toProperties(this.sessionProperties), ImmutableMap.of(), null, clientRequestTimeout); }
public static Date getDate(final SharedPreferences prefs, final String key, final Date defValue) { if (!prefs.contains(key + "_value") || !prefs.contains(key + "_zone")) { return defValue; } Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(prefs.getLong(key + "_value", 0)); calendar.setTimeZone(TimeZone.getTimeZone(prefs.getString(key + "_zone", TimeZone.getDefault().getID()))); return calendar.getTime(); } public static void putDate(final SharedPreferences prefs, final String key, final Date date, final TimeZone zone) { editor.edit().putLong(key + "_value", date.getTime()).apply(); editor.edit().putString(key + "_zone", zone.getID()).apply(); }
TimeZone tz = TimeZone.getDefault(); Date now = new Date(); int offsetFromUtc = tz.getOffset(now.getTime()) / 1000;
public static String toIsoTime(long timestamp) { // Uses old-style dates rather than java.time because // the code still must compile for JDK 7. DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); fmt.setTimeZone(TimeZone.getDefault()); return fmt.format(new Date(timestamp)); }
public String toFreemarkerIsoLocal(Date date) { TimeZone tz = TimeZone.getDefault(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX"); df.setTimeZone(tz); return df.format(date); }
/** * 根据主机的默认 TimeZone,来获得指定形式的时间字符串。 * @param dateFormat * @return 返回日期字符串,形式和formcat一致。 */ public static String getCurrentDateString(String dateFormat) { Calendar cal = Calendar.getInstance(TimeZone.getDefault()); SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); sdf.setTimeZone(TimeZone.getDefault()); return sdf.format(cal.getTime()); }