本文整理了Java中java.util.TimeZone.getDisplayName()
方法的一些代码示例,展示了TimeZone.getDisplayName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TimeZone.getDisplayName()
方法的具体详情如下:
包路径:java.util.TimeZone
类名称:TimeZone
方法名:getDisplayName
[英]Returns a long standard time name of this TimeZone suitable for presentation to the user in the default locale.
This method is equivalent to:
getDisplayName(false,
#LONG,
Locale.getDefault(
Locale.Category#DISPLAY))
[中]返回此时区的长标准时间名称,该名称适合在默认区域设置中呈现给用户。
该方法相当于:
getDisplayName(false,
#LONG,
Locale.getDefault(
Locale.Category#DISPLAY))
代码示例来源:origin: robovm/robovm
/**
* Equivalent to {@code getDisplayName(false, TimeZone.LONG, locale)}.
*/
public final String getDisplayName(Locale locale) {
return getDisplayName(false, LONG, locale);
}
代码示例来源:origin: robovm/robovm
/**
* 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());
}
代码示例来源:origin: robovm/robovm
/**
* 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());
}
代码示例来源:origin: stackoverflow.com
Calendar cal = Calendar.getInstance();
TimeZone tz = cal.getTimeZone();
Log.d("Time zone","="+tz.getDisplayName());
代码示例来源:origin: stackoverflow.com
TimeZone tz = TimeZone.getDefault();
System.out.println("TimeZone "+tz.getDisplayName(false, TimeZone.SHORT)+" Timezon id :: " +tz.getID());
代码示例来源:origin: facebook/facebook-android-sdk
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) {
}
}
代码示例来源:origin: commons-lang/commons-lang
/**
* <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;
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* <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;
}
代码示例来源:origin: ltsopensource/light-task-scheduler
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;
}
代码示例来源:origin: ltsopensource/light-task-scheduler
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;
}
代码示例来源:origin: igniterealtime/Openfire
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;
}
代码示例来源:origin: jphp-group/jphp
@Signature
public Memory getDisplayName(Environment env, Memory... args) {
return StringMemory.valueOf(timeZone.getDisplayName());
}
代码示例来源:origin: com.h2database/h2
/**
* 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());
}
代码示例来源:origin: EngineHub/WorldEdit
@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()));
}
代码示例来源:origin: org.apache.commons/commons-lang3
@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);
}
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@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);
}
}
}
代码示例来源:origin: jphp-group/jphp
@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();
}
代码示例来源:origin: org.apache.commons/commons-lang3
@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()
);
}
}
}
}
}
代码示例来源:origin: org.apache.commons/commons-lang3
@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));
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@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));
}
}
内容来源于网络,如有侵权,请联系作者删除!