java.util.TimeZone.getDefault()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(287)

本文整理了Java中java.util.TimeZone.getDefault()方法的一些代码示例,展示了TimeZone.getDefault()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TimeZone.getDefault()方法的具体详情如下:
包路径:java.util.TimeZone
类名称:TimeZone
方法名:getDefault

TimeZone.getDefault介绍

[英]Gets the default TimeZone for this host. The source of the default TimeZone may vary with implementation.
[中]

代码示例

代码示例来源:origin: neo4j/neo4j

public StoreFiles( DatabaseLayout databaseLayout )
{
  this.databaseLayout = databaseLayout;
  TimeZone tz = TimeZone.getDefault();
  dateFormat = new SimpleDateFormat( FORMAT_DATE_ISO );
  dateFormat.setTimeZone( tz );
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * <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());
}

代码示例来源:origin: prestodb/presto

@Config("hive.time-zone")
public HiveClientConfig setTimeZone(String id)
{
  this.timeZone = (id != null) ? id : TimeZone.getDefault().getID();
  return this;
}

代码示例来源:origin: stackoverflow.com

TimeZone.getDefault().inDaylightTime( new Date() );

代码示例来源:origin: stackoverflow.com

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());

代码示例来源:origin: stackoverflow.com

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");

代码示例来源:origin: stagemonitor/stagemonitor

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);
}

代码示例来源: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: com.thoughtworks.xstream/xstream

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;
}

代码示例来源:origin: robovm/robovm

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);
}

代码示例来源:origin: spring-projects/spring-framework

@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);
  }
}

代码示例来源:origin: org.apache.commons/commons-lang3

@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());
}

代码示例来源:origin: org.apache.commons/commons-lang3

@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);

代码示例来源:origin: dropwizard/dropwizard

@JsonProperty
public void setTimeZone(String zoneId) {
  this.timeZone = Strings.nullToEmpty(zoneId).equalsIgnoreCase("system") ? TimeZone.getDefault() :
    TimeZone.getTimeZone(zoneId);
}

代码示例来源:origin: prestodb/presto

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);
}

代码示例来源:origin: stackoverflow.com

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();
}

代码示例来源:origin: stackoverflow.com

TimeZone tz = TimeZone.getDefault();
Date now = new Date();
int offsetFromUtc = tz.getOffset(now.getTime()) / 1000;

代码示例来源:origin: apache/drill

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));
}

代码示例来源:origin: stagemonitor/stagemonitor

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);
}

代码示例来源:origin: jiangqqlmj/FastDev4Android

/**
 * 根据主机的默认 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());
}

相关文章