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

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

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

TimeZone.useDaylightTime介绍

[英]Queries if this TimeZone uses Daylight Saving Time.

If an underlying TimeZone implementation subclass supports historical and future Daylight Saving Time schedule changes, this method refers to the last known Daylight Saving Time rule that can be a future prediction and may not be the same as the current rule. Consider calling #observesDaylightTime()if the current rule should also be taken into account.
[中]查询此时区是否使用夏令时。
如果基础时区实现子类支持历史和未来的夏令时时间表更改,则此方法将引用上一个已知的夏令时规则,该规则可以是未来的预测,并且可能与当前规则不同。如果还应该考虑当前规则,请考虑调用y.EnvivsDayLimTimeTime()。

代码示例

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

/**
 * Returns the latest daylight savings in milliseconds for this time zone, relative
 * to this time zone's regular UTC offset (as returned by {@link #getRawOffset}).
 *
 * <p>This class returns {@code 3600000} (1 hour) for time zones
 * that use daylight savings time and {@code 0} for timezones that do not,
 * leaving it to subclasses to override this method for other daylight savings
 * offsets. (There are time zones, such as {@code Australia/Lord_Howe},
 * that use other values.)
 *
 * <p>Note that this method doesn't tell you whether or not to <i>apply</i> the
 * offset: you need to call {@code inDaylightTime} for the specific time
 * you're interested in. If this method returns a non-zero offset, that only
 * tells you that this {@code TimeZone} sometimes observes daylight savings.
 *
 * <p>Note also that this method doesn't necessarily return the value you need
 * to apply to the time you're working with. This value can and does change over
 * time for a given time zone.
 *
 * <p>It's highly unlikely that you should ever call this method. You
 * probably want {@link #getOffset} instead, which tells you the offset
 * for a specific point in time, and takes daylight savings into account for you.
 */
public int getDSTSavings() {
  return useDaylightTime() ? 3600000 : 0;
}

代码示例来源:origin: commons-lang/commons-lang

/**
   * {@inheritDoc}
   */
  public void appendTo(StringBuffer buffer, Calendar calendar) {
    if (mTimeZoneForced) {
      if (mTimeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) {
        buffer.append(mDaylight);
      } else {
        buffer.append(mStandard);
      }
    } else {
      TimeZone timeZone = calendar.getTimeZone();
      if (timeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) {
        buffer.append(getTimeZoneDisplay(timeZone, true, mStyle, mLocale));
      } else {
        buffer.append(getTimeZoneDisplay(timeZone, false, mStyle, mLocale));
      }
    }
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

@Override
  public void appendTo(final StringBuffer buffer, final Calendar calendar) {
    final TimeZone zone = calendar.getTimeZone();
    if (zone.useDaylightTime()
        && calendar.get(Calendar.DST_OFFSET) != 0) {
      buffer.append(getTimeZoneDisplay(zone, true, mStyle, mLocale));
    } else {
      buffer.append(getTimeZoneDisplay(zone, false, mStyle, mLocale));
    }
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

@Override
  public void appendTo(final StringBuffer buffer, final Calendar calendar) {
    final TimeZone zone = calendar.getTimeZone();
    if (zone.useDaylightTime()
        && calendar.get(Calendar.DST_OFFSET) != 0) {
      buffer.append(getTimeZoneDisplay(zone, true, mStyle, mLocale));
    } else {
      buffer.append(getTimeZoneDisplay(zone, false, mStyle, mLocale));
    }
  }
}

代码示例来源:origin: igniterealtime/Openfire

@Override
  public void appendTo(StringBuffer buffer, Calendar calendar) {
    TimeZone timeZone;
    if ((timeZone = mTimeZone) != null) {
      if (timeZone.useDaylightTime() &&
        calendar.get(Calendar.DST_OFFSET) != 0) {
        buffer.append(mDaylight);
      }
      else {
        buffer.append(mStandard);
      }
    }
    else {
      timeZone = calendar.getTimeZone();
      if (timeZone.useDaylightTime() &&
        calendar.get(Calendar.DST_OFFSET) != 0) {
        buffer.append(getTimeZoneDisplay
               (timeZone, true, mStyle, mLocale));
      }
      else {
        buffer.append(getTimeZoneDisplay
               (timeZone, false, mStyle, mLocale));
      }
    }
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

TimeZoneStrategy(final Locale locale) {
  final String[][] zones = DateFormatSymbols.getInstance(locale).getZoneStrings();
  for (String[] zone : zones) {
    if (zone[ID].startsWith("GMT")) {
      continue;
    }
    final TimeZone tz = TimeZone.getTimeZone(zone[ID]);
    if (!tzNames.containsKey(zone[LONG_STD])) {
      tzNames.put(zone[LONG_STD], tz);
    }
    if (!tzNames.containsKey(zone[SHORT_STD])) {
      tzNames.put(zone[SHORT_STD], tz);
    }
    if (tz.useDaylightTime()) {
      if (!tzNames.containsKey(zone[LONG_DST])) {
        tzNames.put(zone[LONG_DST], tz);
      }
      if (!tzNames.containsKey(zone[SHORT_DST])) {
        tzNames.put(zone[SHORT_DST], tz);
      }
    }
  }
  final StringBuilder sb = new StringBuilder();
  sb.append("(GMT[+\\-]\\d{0,1}\\d{2}|[+\\-]\\d{2}:?\\d{2}|");
  for (final String id : tzNames.keySet()) {
    escapeRegex(sb, id, false).append('|');
  }
  sb.setCharAt(sb.length() - 1, ')');
  validTimeZoneChars = sb.toString();
}

代码示例来源:origin: ltsopensource/light-task-scheduler

TimeZoneStrategy(final Locale locale) {
  final String[][] zones = DateFormatSymbols.getInstance(locale).getZoneStrings();
  for (String[] zone : zones) {
    if (zone[ID].startsWith("GMT")) {
      continue;
    }
    final TimeZone tz = TimeZone.getTimeZone(zone[ID]);
    if (!tzNames.containsKey(zone[LONG_STD])) {
      tzNames.put(zone[LONG_STD], tz);
    }
    if (!tzNames.containsKey(zone[SHORT_STD])) {
      tzNames.put(zone[SHORT_STD], tz);
    }
    if (tz.useDaylightTime()) {
      if (!tzNames.containsKey(zone[LONG_DST])) {
        tzNames.put(zone[LONG_DST], tz);
      }
      if (!tzNames.containsKey(zone[SHORT_DST])) {
        tzNames.put(zone[SHORT_DST], tz);
      }
    }
  }
  final StringBuilder sb = new StringBuilder();
  sb.append("(GMT[+\\-]\\d{0,1}\\d{2}|[+\\-]\\d{2}:?\\d{2}|");
  for (final String id : tzNames.keySet()) {
    escapeRegex(sb, id, false).append('|');
  }
  sb.setCharAt(sb.length() - 1, ')');
  validTimeZoneChars = sb.toString();
}

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

/** formats time zone specifier. */
private static void formatTimeZone(Calendar cal,StringBuilder buf) {
  TimeZone tz = cal.getTimeZone();
  if (tz == null)      return;
  // otherwise print out normally.
  int offset;
  if (tz.inDaylightTime(cal.getTime())) {
    offset = tz.getRawOffset() + (tz.useDaylightTime()?3600000:0);
  } else {
    offset = tz.getRawOffset();
  }
  if(offset==0) {
    buf.append('Z');
    return;
  }
  if (offset >= 0)
    buf.append('+');
  else {
    buf.append('-');
    offset *= -1;
  }
  offset /= 60 * 1000; // offset is in milli-seconds
  formatTwoDigits(offset / 60, buf);
  buf.append(':');
  formatTwoDigits(offset % 60, buf);
}

代码示例来源:origin: igniterealtime/Openfire

if (zone.inDaylightTime(new Date()) && zone.useDaylightTime()) {
  offset += (int)JiveConstants.HOUR;

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

if (timeZone.useDaylightTime()) {
  for (int year = STARTING_YEAR; year <= endYear; year++) {
    ZonedDateTime i = LocalDateTime.of(year, 1, 1, 0, 0)

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

import java.util.TimeZone;

public class DaylightSavings {
  public static void main(String[] args) {
    TimeZone tz = TimeZone.getTimeZone("Australia/Brisbane");
    System.out.println(tz.useDaylightTime());
  }
}

代码示例来源:origin: edu.internet2.middleware.grouper/grouperClient

/**
   * {@inheritDoc}
   */
  public void appendTo(StringBuffer buffer, Calendar calendar) {
    if (mTimeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) {
      buffer.append(mDaylight);
    } else {
      buffer.append(mStandard);
    }
  }
}

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.oracle

/**
 * Return true if the calendar supports and is in daylight time
 * (according to its timezone), false otherwise
 */
public static boolean shouldAppendDaylightTime(Calendar calendar) {
  if (calendar == null) {
    return false;
  }
  TimeZone zone = calendar.getTimeZone();
  return zone.useDaylightTime() && zone.inDaylightTime(calendar.getTime());
}

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

/**
 * Return true if the calendar supports and is in daylight time
 * (according to its timezone), false otherwise
 */
public static boolean shouldAppendDaylightTime(Calendar calendar) {
  if (calendar == null) {
    return false;
  }
  TimeZone zone = calendar.getTimeZone();
  return zone.useDaylightTime() && zone.inDaylightTime(calendar.getTime());
}

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

for (String tzId : TimeZone.getAvailableIDs()) {
  TimeZone tz = TimeZone.getTimeZone(tzId);
  if (tz.useDaylightTime()) {
    // do something
  }
}

代码示例来源:origin: com.github.ltsopensource/lts-core

@Override
  public void appendTo(final StringBuffer buffer, final Calendar calendar) {
    final TimeZone zone = calendar.getTimeZone();
    if (zone.useDaylightTime()
        && calendar.get(Calendar.DST_OFFSET) != 0) {
      buffer.append(getTimeZoneDisplay(zone, true, mStyle, mLocale));
    } else {
      buffer.append(getTimeZoneDisplay(zone, false, mStyle, mLocale));
    }
  }
}

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

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: org.vx68k.quercus/quercus

public static ArrayValue listAbbreviations()
{
 ArrayValue array = new ArrayValueImpl();
 String []ids = TimeZone.getAvailableIDs();
 for (int i = 0; i < ids.length; i++) {
  TimeZone tz = TimeZone.getTimeZone(ids[i]);
  addAbbreviation(array, tz, false);
  if (tz.useDaylightTime())
   addAbbreviation(array, tz, true);
 }
 return array;
}

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

/**
 * Ensure useDaylightTime() method is working correctly.
 */
public void testUseDaylightTime() {
  assertEquals(expectedUseDaylightTime, timezone.useDaylightTime());
  assertEquals(tz.useDaylightTime(), timezone.useDaylightTime());
}

相关文章