當前位置: 首頁>>代碼示例>>Java>>正文


Java TimeZone.inDaylightTime方法代碼示例

本文整理匯總了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;
}
 
開發者ID:phoenixctms,項目名稱:ctsms,代碼行數:20,代碼來源:DateUtil.java

示例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);
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:28,代碼來源:DERGeneralizedTime.java

示例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));
            }
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:36,代碼來源:TestZoneTextPrinterParser.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:JarEntryTime.java

示例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();
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:23,代碼來源:TriggerUtils.java


注:本文中的java.util.TimeZone.inDaylightTime方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。