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

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

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

TimeZone.getDSTSavings介绍

[英]Returns the amount of time to be added to local standard time to get local wall clock time.

The default implementation returns 3600000 milliseconds (i.e., one hour) if a call to #useDaylightTime()returns true. Otherwise, 0 (zero) is returned.

If an underlying TimeZone implementation subclass supports historical and future Daylight Saving Time schedule changes, this method returns the amount of saving time of the last known Daylight Saving Time rule that can be a future prediction.

If the amount of saving time at any given time stamp is required, construct a Calendar with this TimeZone and the time stamp, and call Calendar#get(int) (Calendar#DST_OFFSET ).
[中]返回要添加到本地标准时间以获取本地挂钟时间的时间量。
如果对#useDaylightTime()的调用返回true,默认实现将返回3600000毫秒(即一小时)。否则,返回0(零)。
如果基础时区实现子类支持历史和未来的夏令时时间表更改,则此方法将返回上一个已知的夏令时规则的节约时间量,该规则可以是未来的预测。
如果需要在任何给定的时间戳上节省时间,请使用此时区和时间戳构造一个日历,并调用Calendar#get(int)(Calendar#DST_OFFSET)。

代码示例

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

TzInfo(final TimeZone tz, final boolean useDst) {
    zone = tz;
    dstOffset = useDst ?tz.getDSTSavings() :0;
  }
}

代码示例来源:origin: looly/hutool

TzInfo(final TimeZone tz, final boolean useDst) {
    zone = tz;
    dstOffset = useDst ? tz.getDSTSavings() : 0;
  }
}

代码示例来源:origin: looly/hutool

TzInfo(final TimeZone tz, final boolean useDst) {
    zone = tz;
    dstOffset = useDst ? tz.getDSTSavings() : 0;
  }
}

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

/**
 * Returns the offset in milliseconds from UTC for this time zone at {@code
 * time}. The offset includes daylight savings time if the specified
 * date is within the daylight savings time period.
 *
 * @param time the date in milliseconds since January 1, 1970 00:00:00 UTC
 */
public int getOffset(long time) {
  if (inDaylightTime(new Date(time))) {
    return getRawOffset() + getDSTSavings();
  }
  return getRawOffset();
}

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

Calendar c = Calendar.getInstance();
 System.out.println("current: "+c.getTime());
 TimeZone z = c.getTimeZone();
 int offset = z.getRawOffset();
 if(z.inDaylightTime(new Date())){
   offset = offset + z.getDSTSavings();
 }
 int offsetHrs = offset / 1000 / 60 / 60;
 int offsetMins = offset / 1000 / 60 % 60;
 System.out.println("offset: " + offsetHrs);
 System.out.println("offset: " + offsetMins);
 c.add(Calendar.HOUR_OF_DAY, (-offsetHrs));
 c.add(Calendar.MINUTE, (-offsetMins));
 System.out.println("GMT Time: "+c.getTime());

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

Calendar subParseZoneString(String text, int j) {
    TimeZone tz = getTimeZone();
    calendar.set(Calendar.DST_OFFSET, j >= 3 ? tz.getDSTSavings() : 0);
    return calendar;

  }
}

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

@Override
protected void computeFields() {
  TimeZone timeZone = getTimeZone();
  int dstOffset = timeZone.inDaylightTime(new Date(time)) ? timeZone.getDSTSavings() : 0;
  int zoneOffset = timeZone.getRawOffset();
  fields[DST_OFFSET] = dstOffset;
  fields[ZONE_OFFSET] = zoneOffset;
  fullFieldsCalc(time, zoneOffset);
  for (int i = 0; i < FIELD_COUNT; i++) {
    isSet[i] = true;
  }
}

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

rawOffset += tz.getDSTSavings();

代码示例来源:origin: org.codehaus.groovy/groovy

/**
 * Get the DST offset (if any) for the default locale and the given date.
 *
 * @param self a Date
 * @return the DST offset as a Duration.
 */
public static Duration getDaylightSavingsOffset(Date self) {
  TimeZone timeZone = getTimeZone(self);
  int millis = (timeZone.useDaylightTime() && timeZone.inDaylightTime(self))
      ? timeZone.getDSTSavings() : 0;
  return new TimeDuration(0, 0, 0, millis);
}

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

int dstSavings = zone.getDSTSavings();

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

earlier.setTimeInMillis(calendar.getTimeInMillis() - timeZone.getDSTSavings());
check = LocalDateTime.fromCalendarFields(earlier);
if (check.equals(this)) {

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

} else if (check.equals(this)) {
  Date earlier = new Date(date.getTime() - TimeZone.getDefault().getDSTSavings());
  if (earlier.getDate() == dom) {
    date = earlier;

代码示例来源:origin: joda-time/joda-time

earlier.setTimeInMillis(calendar.getTimeInMillis() - timeZone.getDSTSavings());
check = LocalDateTime.fromCalendarFields(earlier);
if (check.equals(this)) {

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

offset += getDSTSavings();

代码示例来源:origin: JodaOrg/joda-time

earlier.setTimeInMillis(calendar.getTimeInMillis() - timeZone.getDSTSavings());
check = LocalDateTime.fromCalendarFields(earlier);
if (check.equals(this)) {

代码示例来源:origin: joda-time/joda-time

} else if (check.equals(this)) {
  Date earlier = new Date(date.getTime() - TimeZone.getDefault().getDSTSavings());
  if (earlier.getDate() == dom) {
    date = earlier;

代码示例来源:origin: JodaOrg/joda-time

} else if (check.equals(this)) {
  Date earlier = new Date(date.getTime() - TimeZone.getDefault().getDSTSavings());
  if (earlier.getDate() == dom) {
    date = earlier;

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testFormatLogEventStringBuilderIso8601TimezoneUTC() {
  final LogEvent event = new MyLogEvent();
  final DatePatternConverter converter = DatePatternConverter.newInstance(new String[] {"ISO8601", "UTC"});
  final StringBuilder sb = new StringBuilder();
  converter.format(event, sb);
  final TimeZone tz = TimeZone.getTimeZone("UTC");
  final SimpleDateFormat sdf = new SimpleDateFormat(converter.getPattern());
  sdf.setTimeZone(tz);
  final long adjusted = event.getTimeMillis() + tz.getDSTSavings();
  final String expected = sdf.format(new Date(adjusted));
  // final String expected = "2011-12-30T09:56:35,987";
  assertEquals(expected, sb.toString());
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testFormatLogEventStringBuilderIso8601TimezoneJST() {
  final LogEvent event = new MyLogEvent();
  final String[] optionsWithTimezone = {ISO8601_FORMAT, "JST"};
  final DatePatternConverter converter = DatePatternConverter.newInstance(optionsWithTimezone);
  final StringBuilder sb = new StringBuilder();
  converter.format(event, sb);
  // JST=Japan Standard Time: UTC+9:00
  final TimeZone tz = TimeZone.getTimeZone("JST");
  final SimpleDateFormat sdf = new SimpleDateFormat(converter.getPattern());
  sdf.setTimeZone(tz);
  final long adjusted = event.getTimeMillis() + tz.getDSTSavings();
  final String expected = sdf.format(new Date(adjusted));
  // final String expected = "2011-12-30T18:56:35,987"; // in CET (Central Eastern Time: Amsterdam)
  assertEquals(expected, sb.toString());
}

代码示例来源:origin: googlemaps/google-maps-services-java

@Test
public void testGetTimeZone() throws Exception {
 try (LocalTestServerContext sc =
   new LocalTestServerContext(
     "\n"
       + "{\n"
       + "   \"dstOffset\" : 0,\n"
       + "   \"rawOffset\" : 36000,\n"
       + "   \"status\" : \"OK\",\n"
       + "   \"timeZoneId\" : \"Australia/Sydney\",\n"
       + "   \"timeZoneName\" : \"Australian Eastern Standard Time\"\n"
       + "}\n")) {
  LatLng sydney = new LatLng(-33.8688, 151.2093);
  TimeZone tz = TimeZoneApi.getTimeZone(sc.context, sydney).await();
  assertNotNull(tz);
  assertEquals(TimeZone.getTimeZone("Australia/Sydney"), tz);
  // GMT+10
  assertEquals(36000000, tz.getRawOffset());
  // DST is +1h
  assertEquals(3600000, tz.getDSTSavings());
  assertTrue(tz.inDaylightTime(new Date(1388494800000L)));
  sc.assertParamValue(sydney.toUrlValue(), "location");
 }
}

相关文章