⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpletimezone.java

📁 java源代码 请看看啊 提点宝贵的意见
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * @(#)SimpleTimeZone.java	1.45 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. *//* * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved * (C) Copyright IBM Corp. 1996 - All Rights Reserved * *   The original version of this source code and documentation is copyrighted * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These * materials are provided under terms of a License Agreement between Taligent * and Sun. This technology is protected by multiple US and International * patents. This notice and attribution to Taligent may not be removed. *   Taligent is a registered trademark of Taligent, Inc. * */package java.util;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.IOException;import sun.util.calendar.CalendarDate;import sun.util.calendar.Gregorian;/** * <code>SimpleTimeZone</code> is a concrete subclass of <code>TimeZone</code> * that represents a time zone for use with a Gregorian calendar. * The class holds an offset from GMT, called <em>raw offset</em>, and start * and end rules for a daylight saving time schedule.  Since it only holds * single values for each, it cannot handle historical changes in the offset * from GMT and the daylight saving schedule, except that the {@link * #setStartYear setStartYear} method can specify the year when the daylight * saving time schedule starts in effect. * <p> * To construct a <code>SimpleTimeZone</code> with a daylight saving time * schedule, the schedule can be described with a set of rules, * <em>start-rule</em> and <em>end-rule</em>. A day when daylight saving time * starts or ends is specified by a combination of <em>month</em>, * <em>day-of-month</em>, and <em>day-of-week</em> values. The <em>month</em> * value is represented by a Calendar {@link Calendar#MONTH MONTH} field * value, such as {@link Calendar#MARCH}. The <em>day-of-week</em> value is * represented by a Calendar {@link Calendar#DAY_OF_WEEK DAY_OF_WEEK} value, * such as {@link Calendar#SUNDAY SUNDAY}. The meanings of value combinations * are as follows. * * <ul> * <li><b>Exact day of month</b><br> * To specify an exact day of month, set the <em>month</em> and * <em>day-of-month</em> to an exact value, and <em>day-of-week</em> to zero. For * example, to specify March 1, set the <em>month</em> to {@link Calendar#MARCH * MARCH}, <em>day-of-month</em> to 1, and <em>day-of-week</em> to 0.</li> * * <li><b>Day of week on or after day of month</b><br> * To specify a day of week on or after an exact day of month, set the * <em>month</em> to an exact month value, <em>day-of-month</em> to the day on * or after which the rule is applied, and <em>day-of-week</em> to a {@link * Calendar#DAY_OF_WEEK DAY_OF_WEEK} field value. For example, to specify the * second Sunday of April, set <em>month</em> to {@link Calendar#APRIL APRIL}, * <em>day-of-month</em> to 8, and <em>day-of-week</em> to {@link * Calendar#SUNDAY SUNDAY}.</li> * * <li><b>Day of week on or before day of month</b><br> * To specify a day of the week on or before an exact day of the month, set * <em>day-of-month</em> and <em>day-of-week</em> to a negative value. For * example, to specify the last Wednesday on or before the 21st of March, set * <em>month</em> to {@link Calendar#MARCH MARCH}, <em>day-of-month</em> is -21 * and <em>day-of-week</em> is {@link Calendar#WEDNESDAY -WEDNESDAY}. </li> * * <li><b>Last day-of-week of month</b><br> * To specify, the last day-of-week of the month, set <em>day-of-week</em> to a * {@link Calendar#DAY_OF_WEEK DAY_OF_WEEK} value and <em>day-of-month</em> to * -1. For example, to specify the last Sunday of October, set <em>month</em> * to {@link Calendar#OCTOBER OCTOBER}, <em>day-of-week</em> to {@link * Calendar#SUNDAY SUNDAY} and <em>day-of-month</em> to -1.  </li> * * </ul> * The time of the day at which daylight saving time starts or ends is * specified by a millisecond value within the day. There are three kinds of * <em>mode</em>s to specify the time: {@link #WALL_TIME}, {@link * #STANDARD_TIME} and {@link #UTC_TIME}. For example, if daylight * saving time ends * at 2:00 am in the wall clock time, it can be specified by 7200000 * milliseconds in the {@link #WALL_TIME} mode. In this case, the wall clock time * for an <em>end-rule</em> means the same thing as the daylight time. * <p> * The following are examples of parameters for constructing time zone objects. * <pre><code> *      // Base GMT offset: -8:00 *      // DST starts:      at 2:00am in standard time *      //                  on the first Sunday in April *      // DST ends:        at 2:00am in daylight time *      //                  on the last Sunday in October *      // Save:            1 hour *      SimpleTimeZone(-28800000, *                     "America/Los_Angeles", *                     Calendar.APRIL, 1, -Calendar.SUNDAY, *                     7200000, *                     Calendar.OCTOBER, -1, Calendar.SUNDAY, *                     7200000, *                     3600000) * *      // Base GMT offset: +1:00 *      // DST starts:      at 1:00am in UTC time *      //                  on the last Sunday in March *      // DST ends:        at 1:00am in UTC time *      //                  on the last Sunday in October *      // Save:            1 hour *      SimpleTimeZone(3600000, *                     "Europe/Paris", *                     Calendar.MARCH, -1, Calendar.SUNDAY, *                     3600000, SimpleTimeZone.UTC_TIME, *                     Calendar.OCTOBER, -1, Calendar.SUNDAY, *                     3600000, SimpleTimeZone.UTC_TIME, *                     3600000) * </code></pre> * These parameter rules are also applicable to the set rule methods, such as * <code>setStartRule</code>. * * @since 1.1 * @see      Calendar * @see      GregorianCalendar * @see      TimeZone * @version  1.45 01/23/03 * @author   David Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu */public class SimpleTimeZone extends TimeZone {    /**     * Constructs a SimpleTimeZone with the given base time zone offset from GMT     * and time zone ID with no daylight saving time schedule.     *     * @param rawOffset  The base time zone offset in milliseconds to GMT.     * @param ID         The time zone name that is given to this instance.     */    public SimpleTimeZone(int rawOffset, String ID)    {        this.rawOffset = rawOffset;        setID (ID);        dstSavings = millisPerHour; // In case user sets rules later    }    /**     * Constructs a SimpleTimeZone with the given base time zone offset from     * GMT, time zone ID, and rules for starting and ending the daylight     * time.     * Both <code>startTime</code> and <code>endTime</code> are specified to be     * represented in the wall clock time. The amount of daylight saving is     * assumed to be 3600000 milliseconds (i.e., one hour). This constructor is     * equivalent to:     * <pre><code>     *     SimpleTimeZone(rawOffset,     *                    ID,     *                    startMonth,     *                    startDay,     *                    startDayOfWeek,     *                    startTime,     *                    SimpleTimeZone.{@link #WALL_TIME},     *                    endMonth,     *                    endDay,     *                    endDayOfWeek,     *                    endTime,     *                    SimpleTimeZone.{@link #WALL_TIME},     *                    3600000)     * </code></pre>     *     * @param rawOffset       The given base time zone offset from GMT.     * @param ID              The time zone ID which is given to this object.     * @param startMonth      The daylight saving time starting month. Month is     *                        a {@link Calendar#MONTH MONTH} field value (0-based. e.g., 0     *                        for January).     * @param startDay        The day of the month on which the daylight saving time starts.     *                        See the class description for the special cases of this parameter.     * @param startDayOfWeek  The daylight saving time starting day-of-week.     *                        See the class description for the special cases of this parameter.     * @param startTime       The daylight saving time starting time in local wall clock     *                        time (in milliseconds within the day), which is local     *                        standard time in this case.     * @param endMonth        The daylight saving time ending month. Month is     *                        a {@link Calendar#MONTH MONTH} field     *                        value (0-based. e.g., 9 for October).     * @param endDay          The day of the month on which the daylight saving time ends.     *                        See the class description for the special cases of this parameter.     * @param endDayOfWeek    The daylight saving time ending day-of-week.     *                        See the class description for the special cases of this parameter.     * @param endTime         The daylight saving ending time in local wall clock time,     *                        (in milliseconds within the day) which is local daylight     *                        time in this case.     * @exception IllegalArgumentException if the month, day, dayOfWeek, or time     * parameters are out of range for the start or end rule     */    public SimpleTimeZone(int rawOffset, String ID,                          int startMonth, int startDay, int startDayOfWeek, int startTime,                          int endMonth, int endDay, int endDayOfWeek, int endTime)    {        this(rawOffset, ID,             startMonth, startDay, startDayOfWeek, startTime, WALL_TIME,             endMonth, endDay, endDayOfWeek, endTime, WALL_TIME,             millisPerHour);    }    /**     * Constructs a SimpleTimeZone with the given base time zone offset from     * GMT, time zone ID, and rules for starting and ending the daylight     * time.     * Both <code>startTime</code> and <code>endTime</code> are assumed to be     * represented in the wall clock time. This constructor is equivalent to:     * <pre><code>     *     SimpleTimeZone(rawOffset,     *                    ID,     *                    startMonth,     *                    startDay,     *                    startDayOfWeek,     *                    startTime,     *                    SimpleTimeZone.{@link #WALL_TIME},     *                    endMonth,     *                    endDay,     *                    endDayOfWeek,     *                    endTime,     *                    SimpleTimeZone.{@link #WALL_TIME},     *                    dstSavings)     * </code></pre>     *     * @param rawOffset       The given base time zone offset from GMT.     * @param ID              The time zone ID which is given to this object.     * @param startMonth      The daylight saving time starting month. Month is     *                        a {@link Calendar#MONTH MONTH} field     *                        value (0-based. e.g., 0 for January).     * @param startDay        The day of the month on which the daylight saving time starts.     *                        See the class description for the special cases of this parameter.     * @param startDayOfWeek  The daylight saving time starting day-of-week.     *                        See the class description for the special cases of this parameter.     * @param startTime       The daylight saving time starting time in local wall clock     *                        time, which is local standard time in this case.     * @param endMonth        The daylight saving time ending month. Month is     *                        a {@link Calendar#MONTH MONTH} field     *                        value (0-based. e.g., 9 for October).     * @param endDay          The day of the month on which the daylight saving time ends.     *                        See the class description for the special cases of this parameter.     * @param endDayOfWeek    The daylight saving time ending day-of-week.     *                        See the class description for the special cases of this parameter.     * @param endTime         The daylight saving ending time in local wall clock time,     *                        which is local daylight time in this case.     * @param dstSavings      The amount of time in milliseconds saved during     *                        daylight saving time.     * @exception IllegalArgumentException if the month, day, dayOfWeek, or time     * parameters are out of range for the start or end rule     * @since 1.2     */    public SimpleTimeZone(int rawOffset, String ID,                          int startMonth, int startDay, int startDayOfWeek, int startTime,                          int endMonth, int endDay, int endDayOfWeek, int endTime,                          int dstSavings)    {        this(rawOffset, ID,             startMonth, startDay, startDayOfWeek, startTime, WALL_TIME,             endMonth, endDay, endDayOfWeek, endTime, WALL_TIME,             dstSavings);    }    /**     * Constructs a SimpleTimeZone with the given base time zone offset from     * GMT, time zone ID, and rules for starting and ending the daylight     * time.     * This constructor takes the full set of the start and end rules     * parameters, including modes of <code>startTime</code> and     * <code>endTime</code>. The mode specifies either {@link #WALL_TIME wall     * time} or {@link #STANDARD_TIME standard time} or {@link #UTC_TIME UTC     * time}.     *     * @param rawOffset       The given base time zone offset from GMT.     * @param ID              The time zone ID which is given to this object.     * @param startMonth      The daylight saving time starting month. Month is     *                        a {@link Calendar#MONTH MONTH} field     *                        value (0-based. e.g., 0 for January).     * @param startDay        The day of the month on which the daylight saving time starts.     *                        See the class description for the special cases of this parameter.     * @param startDayOfWeek  The daylight saving time starting day-of-week.     *                        See the class description for the special cases of this parameter.     * @param startTime       The daylight saving time starting time in the time mode     *                        specified by <code>startTimeMode</code>.     * @param startTimeMode   The mode of the start time specified by startTime.     * @param endMonth        The daylight saving time ending month. Month is     *                        a {@link Calendar#MONTH MONTH} field     *                        value (0-based. e.g., 9 for October).     * @param endDay          The day of the month on which the daylight saving time ends.     *                        See the class description for the special cases of this parameter.     * @param endDayOfWeek    The daylight saving time ending day-of-week.     *                        See the class description for the special cases of this parameter.     * @param endTime         The daylight saving ending time in time time mode     *                        specified by <code>endTimeMode</code>.     * @param endTimeMode     The mode of the end time specified by endTime     * @param dstSavings      The amount of time in milliseconds saved during     *                        daylight saving time.     *     * @exception IllegalArgumentException if the month, day, dayOfWeek, time more, or     * time parameters are out of range for the start or end rule, or if a time mode     * value is invalid.     *     * @see #WALL_TIME     * @see #STANDARD_TIME

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -