/** * Equivalent to {@code getDisplayName(false, TimeZone.LONG, locale)}. */ public final String getDisplayName(Locale locale) { return getDisplayName(false, LONG, locale); }
/** * Equivalent to {@code getDisplayName(false, TimeZone.LONG, Locale.getDefault())}. * <a href="../util/Locale.html#default_locale">Be wary of the default locale</a>. */ public final String getDisplayName() { return getDisplayName(false, LONG, Locale.getDefault()); }
/** * Equivalent to {@code getDisplayName(daylightTime, style, Locale.getDefault())}. * <a href="../util/Locale.html#default_locale">Be wary of the default locale</a>. */ public final String getDisplayName(boolean daylightTime, int style) { return getDisplayName(daylightTime, style, Locale.getDefault()); }
Calendar cal = Calendar.getInstance(); TimeZone tz = cal.getTimeZone(); Log.d("Time zone","="+tz.getDisplayName());
TimeZone tz = TimeZone.getDefault(); System.out.println("TimeZone "+tz.getDisplayName(false, TimeZone.SHORT)+" Timezon id :: " +tz.getID());
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) { } }
/** * <p>Gets the time zone display name, using a cache for performance.</p> * * @param tz the zone to query * @param daylight true if daylight savings * @param style the style to use <code>TimeZone.LONG</code> * or <code>TimeZone.SHORT</code> * @param locale the locale to use * @return the textual name of the time zone */ static synchronized String getTimeZoneDisplay(TimeZone tz, boolean daylight, int style, Locale locale) { Object key = new TimeZoneDisplayKey(tz, daylight, style, locale); String value = (String) cTimeZoneDisplayCache.get(key); if (value == null) { // This is a very slow call, so cache the results. value = tz.getDisplayName(daylight, style, locale); cTimeZoneDisplayCache.put(key, value); } return value; }
/** * <p>Gets the time zone display name, using a cache for performance.</p> * * @param tz the zone to query * @param daylight true if daylight savings * @param style the style to use {@code TimeZone.LONG} or {@code TimeZone.SHORT} * @param locale the locale to use * @return the textual name of the time zone */ static String getTimeZoneDisplay(final TimeZone tz, final boolean daylight, final int style, final Locale locale) { final TimeZoneDisplayKey key = new TimeZoneDisplayKey(tz, daylight, style, locale); String value = cTimeZoneDisplayCache.get(key); if (value == null) { // This is a very slow call, so cache the results. value = tz.getDisplayName(daylight, style, locale); final String prior = cTimeZoneDisplayCache.putIfAbsent(key, value); if (prior != null) { value= prior; } } return value; }
static String getTimeZoneDisplay(final TimeZone tz, final boolean daylight, final int style, final Locale locale) { final TimeZoneDisplayKey key = new TimeZoneDisplayKey(tz, daylight, style, locale); String value = cTimeZoneDisplayCache.get(key); if (value == null) { // This is a very slow call, so cache the results. value = tz.getDisplayName(daylight, style, locale); final String prior = cTimeZoneDisplayCache.putIfAbsent(key, value); if (prior != null) { value= prior; } } return value; }
static String getTimeZoneDisplay(final TimeZone tz, final boolean daylight, final int style, final Locale locale) { final TimeZoneDisplayKey key = new TimeZoneDisplayKey(tz, daylight, style, locale); String value = cTimeZoneDisplayCache.get(key); if (value == null) { // This is a very slow call, so cache the results. value = tz.getDisplayName(daylight, style, locale); final String prior = cTimeZoneDisplayCache.putIfAbsent(key, value); if (prior != null) { value= prior; } } return value; }
static synchronized String getTimeZoneDisplay(TimeZone tz, boolean daylight, int style, Locale locale) { Object key = new TimeZoneDisplayKey(tz, daylight, style, locale); String value = cTimeZoneDisplayCache.get(key); if (value == null) { // This is a very slow call, so cache the results. value = tz.getDisplayName(daylight, style, locale); cTimeZoneDisplayCache.put(key, value); } return value; }
@Signature public Memory getDisplayName(Environment env, Memory... args) { return StringMemory.valueOf(timeZone.getDisplayName()); }
/** * Returns time zone display name or ID for the specified date-time value. * * @param value * value * @param tzd * if {@code true} return TZD (time zone region with Daylight Saving * Time information included), if {@code false} return TZR (time zone * region) * @return time zone display name or ID */ private static String getTimeZone(Value value, boolean tzd) { if (!(value instanceof ValueTimestampTimeZone)) { TimeZone tz = TimeZone.getDefault(); if (tzd) { boolean daylight = tz.inDaylightTime(value.getTimestamp()); return tz.getDisplayName(daylight, TimeZone.SHORT); } return tz.getID(); } return DateTimeUtils.timeZoneNameFromOffsetMins(((ValueTimestampTimeZone) value).getTimeZoneOffsetMins()); }
@Command( aliases = { "tz" }, usage = "[timezone]", desc = "Set your timezone for snapshots", min = 1, max = 1 ) public void tz(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { TimeZone tz = TimeZone.getTimeZone(args.getString(0)); session.setTimezone(tz); player.print("Timezone set for this session to: " + tz.getDisplayName()); player.print("The current time in that timezone is: " + dateFormat.format(Calendar.getInstance(tz).getTime())); }
@Test public void testTzParses() throws Exception { // Check that all Locales can parse the time formats we use for(final Locale locale : Locale.getAvailableLocales()) { final FastDateParser fdp= new FastDateParser("yyyy/MM/dd z", TimeZone.getDefault(), locale); for(final TimeZone tz : new TimeZone[]{NEW_YORK, REYKJAVIK, GMT}) { final Calendar cal= Calendar.getInstance(tz, locale); cal.clear(); cal.set(Calendar.YEAR, 2000); cal.set(Calendar.MONTH, 1); cal.set(Calendar.DAY_OF_MONTH, 10); final Date expected= cal.getTime(); final Date actual = fdp.parse("2000/02/10 "+tz.getDisplayName(locale)); assertEquals("tz:"+tz.getID()+" locale:"+locale.getDisplayName(), expected, actual); } } }
@Test public void testTzParses() throws Exception { // Check that all Locales can parse the time formats we use for(final Locale locale : Locale.getAvailableLocales()) { final FastDateParser fdp= new FastDateParser("yyyy/MM/dd z", TimeZone.getDefault(), locale); for(final TimeZone tz : new TimeZone[]{NEW_YORK, REYKJAVIK, GMT}) { final Calendar cal= Calendar.getInstance(tz, locale); cal.clear(); cal.set(Calendar.YEAR, 2000); cal.set(Calendar.MONTH, 1); cal.set(Calendar.DAY_OF_MONTH, 10); final Date expected= cal.getTime(); final Date actual = fdp.parse("2000/02/10 "+tz.getDisplayName(locale)); Assert.assertEquals("tz:"+tz.getID()+" locale:"+locale.getDisplayName(), expected, actual); } } }
@Signature public Memory __debugInfo(Environment env, Memory... args) { ArrayMemory r = new ArrayMemory(); r.refOfIndex("*id").assign(timeZone.getID()); r.refOfIndex("*rawOffset").assign(timeZone.getRawOffset()); r.refOfIndex("*name").assign(timeZone.getDisplayName()); return r.toConstant(); }
@Test public void testTimeZoneStrategyPattern() { for(final Locale locale : Locale.getAvailableLocales()) { final FastDateParser parser = new FastDateParser("z", TimeZone.getDefault(), locale); final String[][] zones = DateFormatSymbols.getInstance(locale).getZoneStrings(); for(final String[] zone : zones) { for(int t = 1; t<zone.length; ++t) { final String tzDisplay = zone[t]; if (tzDisplay == null) { break; } try { parser.parse(tzDisplay); } catch(final Exception ex) { fail("'" + tzDisplay + "'" + " Locale: '" + locale.getDisplayName() + "'" + " TimeZone: " + zone[0] + " offset: " + t + " defaultLocale: " + Locale.getDefault() + " defaultTimeZone: " + TimeZone.getDefault().getDisplayName() ); } } } } }
@Test public void test1806() throws ParseException { final String formatStub = "yyyy-MM-dd'T'HH:mm:ss.SSS"; final String dateStub = "2001-02-04T12:08:56.235"; for (final Expected1806 trial : Expected1806.values()) { final Calendar cal = initializeCalendar(trial.zone); final String message = trial.zone.getDisplayName()+";"; DateParser parser = getInstance(formatStub+"X", trial.zone); assertEquals(message+trial.one, cal.getTime().getTime(), parser.parse(dateStub+trial.one).getTime()-trial.offset); parser = getInstance(formatStub+"XX", trial.zone); assertEquals(message+trial.two, cal.getTime(), parser.parse(dateStub+trial.two)); parser = getInstance(formatStub+"XXX", trial.zone); assertEquals(message+trial.three, cal.getTime(), parser.parse(dateStub+trial.three)); } }
@Test public void test1806() throws ParseException { final String formatStub = "yyyy-MM-dd'T'HH:mm:ss.SSS"; final String dateStub = "2001-02-04T12:08:56.235"; for (final Expected1806 trial : Expected1806.values()) { final Calendar cal = initializeCalendar(trial.zone); final String message = trial.zone.getDisplayName()+";"; DateParser parser = getInstance(formatStub+"X", trial.zone); assertEquals(message+trial.one, cal.getTime().getTime(), parser.parse(dateStub+trial.one).getTime()-trial.offset); parser = getInstance(formatStub+"XX", trial.zone); assertEquals(message+trial.two, cal.getTime(), parser.parse(dateStub+trial.two)); parser = getInstance(formatStub+"XXX", trial.zone); assertEquals(message+trial.three, cal.getTime(), parser.parse(dateStub+trial.three)); } }