Refine search
/** * Parse the given {@code timeZoneString} value into a {@link TimeZone}. * @param timeZoneString the time zone {@code String}, following {@link TimeZone#getTimeZone(String)} * but throwing {@link IllegalArgumentException} in case of an invalid time zone specification * @return a corresponding {@link TimeZone} instance * @throws IllegalArgumentException in case of an invalid time zone specification */ public static TimeZone parseTimeZoneString(String timeZoneString) { TimeZone timeZone = TimeZone.getTimeZone(timeZoneString); if ("GMT".equals(timeZone.getID()) && !timeZoneString.startsWith("GMT")) { // We don't want that GMT fallback... throw new IllegalArgumentException("Invalid time zone specification '" + timeZoneString + "'"); } return timeZone; }
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(); }
@Config("hive.time-zone") public HiveClientConfig setTimeZone(String id) { this.timeZone = (id != null) ? id : TimeZone.getDefault().getID(); return this; }
/** * Parse the given {@code timeZoneString} value into a {@link TimeZone}. * @param timeZoneString the time zone {@code String}, following {@link TimeZone#getTimeZone(String)} * but throwing {@link IllegalArgumentException} in case of an invalid time zone specification * @return a corresponding {@link TimeZone} instance * @throws IllegalArgumentException in case of an invalid time zone specification */ public static TimeZone parseTimeZoneString(String timeZoneString) { TimeZone timeZone = TimeZone.getTimeZone(timeZoneString); if ("GMT".equals(timeZone.getID()) && !timeZoneString.startsWith("GMT")) { // We don't want that GMT fallback... throw new IllegalArgumentException("Invalid time zone specification '" + timeZoneString + "'"); } return timeZone; }
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());
TimeZone tz = TimeZone.getDefault(); System.out.println("TimeZone "+tz.getDisplayName(false, TimeZone.SHORT)+" Timezon id :: " +tz.getID());
/** * Parse the given {@code timeZoneString} value into a {@link TimeZone}. * @param timeZoneString the time zone {@code String}, following {@link TimeZone#getTimeZone(String)} * but throwing {@link IllegalArgumentException} in case of an invalid time zone specification * @return a corresponding {@link TimeZone} instance * @throws IllegalArgumentException in case of an invalid time zone specification */ public static TimeZone parseTimeZoneString(String timeZoneString) { TimeZone timeZone = TimeZone.getTimeZone(timeZoneString); if ("GMT".equals(timeZone.getID()) && !timeZoneString.startsWith("GMT")) { // We don't want that GMT fallback... throw new IllegalArgumentException("Invalid time zone specification '" + timeZoneString + "'"); } return timeZone; }
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; }
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 TimeZone build() { TimeZone timeZone = TimeZone.getTimeZone(timeZoneId); if (timeZone.getID().equals("GMT") && !timeZoneId.equals("GMT") && !timeZoneId.equals("UTC") && !timeZoneId.equals("GMT+00") && !timeZoneId.equals("GMT+00:00") && !timeZoneId.equals("GMT+0000")) { throw new IllegalArgumentException("Unrecognized time zone: " + timeZoneId); } return timeZone; }
@OnScheduled public void OnScheduled(final ProcessContext context) { // Configure jackson mapper before spawning onTriggers final SimpleModule module = new SimpleModule() .addSerializer(MacAddress.class, new MacAddressToStringSerializer()); mapper.registerModule(module); mapper.setDateFormat(this.simpleDateFormat); switch (context.getProperty(TIME_REPRESENTATION).getValue()) { case LOCAL_TZ: // set the mapper TZ to local TZ mapper.setTimeZone(TimeZone.getDefault()); tzId = TimeZone.getDefault().getID(); break; case UTC: // set the mapper TZ to local TZ mapper.setTimeZone(TimeZone.getTimeZone(UTC)); tzId = UTC; break; } }
String timezoneID = TimeZone.getDefault().getID(); System.out.println(timezoneID);
@Implementation(maxSdk = KITKAT_WATCH) protected boolean parse(String timeString) { TimeZone tz; if (timeString.endsWith("Z")) { timeString = timeString.substring(0, timeString.length() - 1); tz = TimeZone.getTimeZone("UTC"); } else { tz = TimeZone.getTimeZone(time.timezone); } SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.ENGLISH); SimpleDateFormat dfShort = new SimpleDateFormat("yyyyMMdd", Locale.ENGLISH); df.setTimeZone(tz); dfShort.setTimeZone(tz); time.timezone = tz.getID(); try { set(df.parse(timeString).getTime()); } catch (ParseException e) { try { set(dfShort.parse(timeString).getTime()); } catch (ParseException e2) { throwTimeFormatException(e2.getLocalizedMessage()); } } return "UTC".equals(tz.getID()); }
@Before public void setUp() { context = ApplicationProvider.getApplicationContext(); alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); shadowAlarmManager = shadowOf(alarmManager); activity = Robolectric.setupActivity(Activity.class); TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); assertThat(TimeZone.getDefault().getID()).isEqualTo("America/Los_Angeles"); }
@Implementation(maxSdk = KITKAT_WATCH) protected static String getCurrentTimezone() { return TimeZone.getDefault().getID(); }
if (index > 20) { String tzStr = strVal.substring(index + 1); TimeZone timeZone = TimeZone.getTimeZone(tzStr); if (!"GMT".equals(timeZone.getID())) { String subStr = strVal.substring(0, index); JSONScanner dateLexer = new JSONScanner(subStr);
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 = " londonTimeZone = TimeZone.getTimeZone("GMT"); newYorkTimeZone = TimeZone.getTimeZone("GMT-5"); sydneyTimeZone = TimeZone.getTimeZone("GMT+10");
String string = "2013-03-05T18:05:05.000Z"; String defaultTimezone = TimeZone.getDefault().getID(); Date date = (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")).parse(string.replaceAll("Z$", "+0000")); System.out.println("string: " + string); System.out.println("defaultTimezone: " + defaultTimezone); System.out.println("date: " + (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")).format(date));
/** * Returns the time zone object for the name (or ID). This differs from * {@link TimeZone#getTimeZone(String)} in that the latest returns GMT * if it doesn't recognize the name, while this throws an * {@link UnrecognizedTimeZoneException}. * * @throws UnrecognizedTimeZoneException If the time zone name wasn't understood */ public static TimeZone getTimeZone(String name) throws UnrecognizedTimeZoneException { if (isGMTish(name)) { if (name.equalsIgnoreCase("UTC")) { return UTC; } return TimeZone.getTimeZone(name); } TimeZone tz = TimeZone.getTimeZone(name); if (isGMTish(tz.getID())) { throw new UnrecognizedTimeZoneException(name); } return tz; }
@Test public void testConvertFromTimestamp2() { TimeZone defaultZone = TimeZone.getDefault(); try { // Use system zone when converting from timestamp to timestamptz String s = "2017-06-12 23:12:56.34"; TimestampTZ tstz1 = TimestampTZUtil.parse(s + " " + TimeZone.getTimeZone("Europe/London").getID()); TimestampTZ tstz2 = TimestampTZUtil.parse(s + " " + TimeZone.getTimeZone("America/Los_Angeles").getID()); Assert.assertTrue(tstz1.compareTo(tstz2) < 0); } finally { TimeZone.setDefault(defaultZone); } } }