本文整理匯總了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();
}