当前位置: 首页>>代码示例>>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;未经允许,请勿转载。