本文整理汇总了Java中java.util.TimeZone.inDaylightTime方法的典型用法代码示例。如果您正苦于以下问题:Java TimeZone.inDaylightTime方法的具体用法?Java TimeZone.inDaylightTime怎么用?Java TimeZone.inDaylightTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.TimeZone
的用法示例。
在下文中一共展示了TimeZone.inDaylightTime方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sanitizeScheduleTimestamp
import java.util.TimeZone; //导入方法依赖的package包/类
public static Date sanitizeScheduleTimestamp(boolean add, Date date) {
if (date != null) {
if (Settings.getBoolean(SettingCodes.ENABLE_PRIMEFACES_SCHEDULE_DST_WORKAROUND, Bundle.SETTINGS, DefaultSettings.ENABLE_PRIMEFACES_SCHEDULE_DST_WORKAROUND)) {
TimeZone timeZone = WebUtil.getTimeZone();
if (timeZone != null) {
if (timeZone.inDaylightTime(new Date())) {
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(GregorianCalendar.MILLISECOND, (add ? 1 : -1) * timeZone.getDSTSavings());
return cal.getTime();
}
} else {
return null;
}
}
return new Date(date.getTime());
}
return null;
}
示例2: calculateGMTOffset
import java.util.TimeZone; //导入方法依赖的package包/类
private String calculateGMTOffset()
{
String sign = "+";
TimeZone timeZone = TimeZone.getDefault();
int offset = timeZone.getRawOffset();
if (offset < 0)
{
sign = "-";
offset = -offset;
}
int hours = offset / (60 * 60 * 1000);
int minutes = (offset - (hours * 60 * 60 * 1000)) / (60 * 1000);
try
{
if (timeZone.useDaylightTime() && timeZone.inDaylightTime(this.getDate()))
{
hours += sign.equals("+") ? 1 : -1;
}
}
catch (ParseException e)
{
// we'll do our best and ignore daylight savings
}
return "GMT" + sign + convert(hours) + ":" + convert(minutes);
}
示例3: test_printText
import java.util.TimeZone; //导入方法依赖的package包/类
public void test_printText() {
Random r = RandomFactory.getRandom();
int N = 8;
Locale[] locales = Locale.getAvailableLocales();
Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
ZonedDateTime zdt = ZonedDateTime.now();
//System.out.printf("locale==%d, timezone=%d%n", locales.length, zids.size());
while (N-- > 0) {
zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
.with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
for (String zid : zids) {
if (zid.equals("ROC") || zid.startsWith("Etc/GMT")) {
continue; // TBD: match jdk behavior?
}
zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
TimeZone tz = TimeZone.getTimeZone(zid);
boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
for (Locale locale : locales) {
String longDisplayName = tz.getDisplayName(isDST, TimeZone.LONG, locale);
String shortDisplayName = tz.getDisplayName(isDST, TimeZone.SHORT, locale);
if ((longDisplayName.startsWith("GMT+") && shortDisplayName.startsWith("GMT+"))
|| (longDisplayName.startsWith("GMT-") && shortDisplayName.startsWith("GMT-"))) {
printText(locale, zdt, TextStyle.FULL, tz, tz.getID());
printText(locale, zdt, TextStyle.SHORT, tz, tz.getID());
continue;
}
printText(locale, zdt, TextStyle.FULL, tz,
tz.getDisplayName(isDST, TimeZone.LONG, locale));
printText(locale, zdt, TextStyle.SHORT, tz,
tz.getDisplayName(isDST, TimeZone.SHORT, locale));
}
}
}
}
示例4: isTimeSettingChanged
import java.util.TimeZone; //导入方法依赖的package包/类
private static boolean isTimeSettingChanged() {
TimeZone currentTZ = TimeZone.getDefault();
boolean currentDST = currentTZ.inDaylightTime(new Date());
return (!currentTZ.equals(TZ) || currentDST != DST);
}
示例5: getOffset
import java.util.TimeZone; //导入方法依赖的package包/类
/**
* Gets the offset from UT for the given date in the given time zone,
* taking into account daylight savings.
*
* <p>
* Equivalent of TimeZone.getOffset(date) in JDK 1.4, but Quartz is trying
* to support JDK 1.3.
* </p>
*
* @param date the date (in milliseconds) that is the base for the offset
* @param tz the time-zone to calculate to offset to
* @return the offset
* @deprecated use TimeZone.getOffset(date)
*/
public static int getOffset(long date, TimeZone tz) {
if (tz.inDaylightTime(new Date(date))) {
return tz.getRawOffset() + getDSTSavings(tz);
}
return tz.getRawOffset();
}