Java Code Examples for sun.util.calendar.BaseCalendar#newCalendarDate()

The following examples show how to use sun.util.calendar.BaseCalendar#newCalendarDate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleTimeZone.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see TimeZone#getOffsets
 */
int getOffsets(long date, int[] offsets) {
    int offset = rawOffset;

  computeOffset:
    if (useDaylight) {
        synchronized (this) {
            if (cacheStart != 0) {
                if (date >= cacheStart && date < cacheEnd) {
                    offset += dstSavings;
                    break computeOffset;
                }
            }
        }
        BaseCalendar cal = date >= GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER ?
            gcal : (BaseCalendar) CalendarSystem.forName("julian");
        BaseCalendar.Date cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
        // Get the year in local time
        cal.getCalendarDate(date + rawOffset, cdate);
        int year = cdate.getNormalizedYear();
        if (year >= startYear) {
            // Clear time elements for the transition calculations
            cdate.setTimeOfDay(0, 0, 0, 0);
            offset = getOffset(cal, cdate, year, date);
        }
    }

    if (offsets != null) {
        offsets[0] = rawOffset;
        offsets[1] = offset - rawOffset;
    }
    return offset;
}
 
Example 2
Source File: GregorianCalendar.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private void setGregorianChange(long cutoverTime) {
    gregorianCutover = cutoverTime;
    gregorianCutoverDate = CalendarUtils.floorDivide(cutoverTime, ONE_DAY)
                            + EPOCH_OFFSET;

    // To provide the "pure" Julian calendar as advertised.
    // Strictly speaking, the last millisecond should be a
    // Gregorian date. However, the API doc specifies that setting
    // the cutover date to Long.MAX_VALUE will make this calendar
    // a pure Julian calendar. (See 4167995)
    if (cutoverTime == Long.MAX_VALUE) {
        gregorianCutoverDate++;
    }

    BaseCalendar.Date d = getGregorianCutoverDate();

    // Set the cutover year (in the Gregorian year numbering)
    gregorianCutoverYear = d.getYear();

    BaseCalendar julianCal = getJulianCalendarSystem();
    d = (BaseCalendar.Date) julianCal.newCalendarDate(TimeZone.NO_TIMEZONE);
    julianCal.getCalendarDateFromFixedDate(d, gregorianCutoverDate - 1);
    gregorianCutoverYearJulian = d.getNormalizedYear();

    if (time < gregorianCutover) {
        // The field values are no longer valid under the new
        // cutover date.
        setUnnormalized();
    }
}
 
Example 3
Source File: GregorianCalendar.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a CalendarDate produced from the specified fixed date.
 *
 * @param fd the fixed date
 */
private BaseCalendar.Date getCalendarDate(long fd) {
    BaseCalendar cal = (fd >= gregorianCutoverDate) ? gcal : getJulianCalendarSystem();
    BaseCalendar.Date d = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
    cal.getCalendarDateFromFixedDate(d, fd);
    return d;
}
 
Example 4
Source File: GregorianCalendar.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void setGregorianChange(long cutoverTime) {
    gregorianCutover = cutoverTime;
    gregorianCutoverDate = CalendarUtils.floorDivide(cutoverTime, ONE_DAY)
                            + EPOCH_OFFSET;

    // To provide the "pure" Julian calendar as advertised.
    // Strictly speaking, the last millisecond should be a
    // Gregorian date. However, the API doc specifies that setting
    // the cutover date to Long.MAX_VALUE will make this calendar
    // a pure Julian calendar. (See 4167995)
    if (cutoverTime == Long.MAX_VALUE) {
        gregorianCutoverDate++;
    }

    BaseCalendar.Date d = getGregorianCutoverDate();

    // Set the cutover year (in the Gregorian year numbering)
    gregorianCutoverYear = d.getYear();

    BaseCalendar julianCal = getJulianCalendarSystem();
    d = (BaseCalendar.Date) julianCal.newCalendarDate(TimeZone.NO_TIMEZONE);
    julianCal.getCalendarDateFromFixedDate(d, gregorianCutoverDate - 1);
    gregorianCutoverYearJulian = d.getNormalizedYear();

    if (time < gregorianCutover) {
        // The field values are no longer valid under the new
        // cutover date.
        setUnnormalized();
    }
}
 
Example 5
Source File: GregorianCalendar.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
private void setGregorianChange(long cutoverTime) {
    gregorianCutover = cutoverTime;
    gregorianCutoverDate = CalendarUtils.floorDivide(cutoverTime, ONE_DAY)
                            + EPOCH_OFFSET;

    // To provide the "pure" Julian calendar as advertised.
    // Strictly speaking, the last millisecond should be a
    // Gregorian date. However, the API doc specifies that setting
    // the cutover date to Long.MAX_VALUE will make this calendar
    // a pure Julian calendar. (See 4167995)
    if (cutoverTime == Long.MAX_VALUE) {
        gregorianCutoverDate++;
    }

    BaseCalendar.Date d = getGregorianCutoverDate();

    // Set the cutover year (in the Gregorian year numbering)
    gregorianCutoverYear = d.getYear();

    BaseCalendar julianCal = getJulianCalendarSystem();
    d = (BaseCalendar.Date) julianCal.newCalendarDate(TimeZone.NO_TIMEZONE);
    julianCal.getCalendarDateFromFixedDate(d, gregorianCutoverDate - 1);
    gregorianCutoverYearJulian = d.getNormalizedYear();

    if (time < gregorianCutover) {
        // The field values are no longer valid under the new
        // cutover date.
        setUnnormalized();
    }
}
 
Example 6
Source File: SimpleTimeZone.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * @see TimeZone#getOffsets
 */
int getOffsets(long date, int[] offsets) {
    int offset = rawOffset;

  computeOffset:
    if (useDaylight) {
        synchronized (this) {
            if (cacheStart != 0) {
                if (date >= cacheStart && date < cacheEnd) {
                    offset += dstSavings;
                    break computeOffset;
                }
            }
        }
        BaseCalendar cal = date >= GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER ?
            gcal : (BaseCalendar) CalendarSystem.forName("julian");
        BaseCalendar.Date cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
        // Get the year in local time
        cal.getCalendarDate(date + rawOffset, cdate);
        int year = cdate.getNormalizedYear();
        if (year >= startYear) {
            // Clear time elements for the transition calculations
            cdate.setTimeOfDay(0, 0, 0, 0);
            offset = getOffset(cal, cdate, year, date);
        }
    }

    if (offsets != null) {
        offsets[0] = rawOffset;
        offsets[1] = offset - rawOffset;
    }
    return offset;
}
 
Example 7
Source File: SimpleTimeZone.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * @see TimeZone#getOffsets
 */
int getOffsets(long date, int[] offsets) {
    int offset = rawOffset;

  computeOffset:
    if (useDaylight) {
        synchronized (this) {
            if (cacheStart != 0) {
                if (date >= cacheStart && date < cacheEnd) {
                    offset += dstSavings;
                    break computeOffset;
                }
            }
        }
        BaseCalendar cal = date >= GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER ?
            gcal : (BaseCalendar) CalendarSystem.forName("julian");
        BaseCalendar.Date cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
        // Get the year in local time
        cal.getCalendarDate(date + rawOffset, cdate);
        int year = cdate.getNormalizedYear();
        if (year >= startYear) {
            // Clear time elements for the transition calculations
            cdate.setTimeOfDay(0, 0, 0, 0);
            offset = getOffset(cal, cdate, year, date);
        }
    }

    if (offsets != null) {
        offsets[0] = rawOffset;
        offsets[1] = offset - rawOffset;
    }
    return offset;
}
 
Example 8
Source File: GregorianCalendar.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void setGregorianChange(long cutoverTime) {
    gregorianCutover = cutoverTime;
    gregorianCutoverDate = CalendarUtils.floorDivide(cutoverTime, ONE_DAY)
                            + EPOCH_OFFSET;

    // To provide the "pure" Julian calendar as advertised.
    // Strictly speaking, the last millisecond should be a
    // Gregorian date. However, the API doc specifies that setting
    // the cutover date to Long.MAX_VALUE will make this calendar
    // a pure Julian calendar. (See 4167995)
    if (cutoverTime == Long.MAX_VALUE) {
        gregorianCutoverDate++;
    }

    BaseCalendar.Date d = getGregorianCutoverDate();

    // Set the cutover year (in the Gregorian year numbering)
    gregorianCutoverYear = d.getYear();

    BaseCalendar julianCal = getJulianCalendarSystem();
    d = (BaseCalendar.Date) julianCal.newCalendarDate(TimeZone.NO_TIMEZONE);
    julianCal.getCalendarDateFromFixedDate(d, gregorianCutoverDate - 1);
    gregorianCutoverYearJulian = d.getNormalizedYear();

    if (time < gregorianCutover) {
        // The field values are no longer valid under the new
        // cutover date.
        setUnnormalized();
    }
}
 
Example 9
Source File: GregorianCalendar.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a CalendarDate produced from the specified fixed date.
 *
 * @param fd the fixed date
 */
private BaseCalendar.Date getCalendarDate(long fd) {
    BaseCalendar cal = (fd >= gregorianCutoverDate) ? gcal : getJulianCalendarSystem();
    BaseCalendar.Date d = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
    cal.getCalendarDateFromFixedDate(d, fd);
    return d;
}
 
Example 10
Source File: GregorianCalendar.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a CalendarDate produced from the specified fixed date.
 *
 * @param fd the fixed date
 */
private BaseCalendar.Date getCalendarDate(long fd) {
    BaseCalendar cal = (fd >= gregorianCutoverDate) ? gcal : getJulianCalendarSystem();
    BaseCalendar.Date d = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
    cal.getCalendarDateFromFixedDate(d, fd);
    return d;
}
 
Example 11
Source File: SimpleTimeZone.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * @see TimeZone#getOffsets
 */
int getOffsets(long date, int[] offsets) {
    int offset = rawOffset;

  computeOffset:
    if (useDaylight) {
        synchronized (this) {
            if (cacheStart != 0) {
                if (date >= cacheStart && date < cacheEnd) {
                    offset += dstSavings;
                    break computeOffset;
                }
            }
        }
        BaseCalendar cal = date >= GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER ?
            gcal : (BaseCalendar) CalendarSystem.forName("julian");
        BaseCalendar.Date cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
        // Get the year in local time
        cal.getCalendarDate(date + rawOffset, cdate);
        int year = cdate.getNormalizedYear();
        if (year >= startYear) {
            // Clear time elements for the transition calculations
            cdate.setTimeOfDay(0, 0, 0, 0);
            offset = getOffset(cal, cdate, year, date);
        }
    }

    if (offsets != null) {
        offsets[0] = rawOffset;
        offsets[1] = offset - rawOffset;
    }
    return offset;
}
 
Example 12
Source File: GregorianCalendar.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void setGregorianChange(long cutoverTime) {
    gregorianCutover = cutoverTime;
    gregorianCutoverDate = CalendarUtils.floorDivide(cutoverTime, ONE_DAY)
                            + EPOCH_OFFSET;

    // To provide the "pure" Julian calendar as advertised.
    // Strictly speaking, the last millisecond should be a
    // Gregorian date. However, the API doc specifies that setting
    // the cutover date to Long.MAX_VALUE will make this calendar
    // a pure Julian calendar. (See 4167995)
    if (cutoverTime == Long.MAX_VALUE) {
        gregorianCutoverDate++;
    }

    BaseCalendar.Date d = getGregorianCutoverDate();

    // Set the cutover year (in the Gregorian year numbering)
    gregorianCutoverYear = d.getYear();

    BaseCalendar julianCal = getJulianCalendarSystem();
    d = (BaseCalendar.Date) julianCal.newCalendarDate(TimeZone.NO_TIMEZONE);
    julianCal.getCalendarDateFromFixedDate(d, gregorianCutoverDate - 1);
    gregorianCutoverYearJulian = d.getNormalizedYear();

    if (time < gregorianCutover) {
        // The field values are no longer valid under the new
        // cutover date.
        setUnnormalized();
    }
}
 
Example 13
Source File: SimpleTimeZone.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see TimeZone#getOffsets
 */
int getOffsets(long date, int[] offsets) {
    int offset = rawOffset;

  computeOffset:
    if (useDaylight) {
        synchronized (this) {
            if (cacheStart != 0) {
                if (date >= cacheStart && date < cacheEnd) {
                    offset += dstSavings;
                    break computeOffset;
                }
            }
        }
        BaseCalendar cal = date >= GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER ?
            gcal : (BaseCalendar) CalendarSystem.forName("julian");
        BaseCalendar.Date cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
        // Get the year in local time
        cal.getCalendarDate(date + rawOffset, cdate);
        int year = cdate.getNormalizedYear();
        if (year >= startYear) {
            // Clear time elements for the transition calculations
            cdate.setTimeOfDay(0, 0, 0, 0);
            offset = getOffset(cal, cdate, year, date);
        }
    }

    if (offsets != null) {
        offsets[0] = rawOffset;
        offsets[1] = offset - rawOffset;
    }
    return offset;
}
 
Example 14
Source File: Date.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Allocates a <code>Date</code> object and initializes it so that
 * it represents the instant at the start of the second specified
 * by the <code>year</code>, <code>month</code>, <code>date</code>,
 * <code>hrs</code>, <code>min</code>, and <code>sec</code> arguments,
 * in the local time zone.
 *
 * @param   year    the year minus 1900.
 * @param   month   the month between 0-11.
 * @param   date    the day of the month between 1-31.
 * @param   hrs     the hours between 0-23.
 * @param   min     the minutes between 0-59.
 * @param   sec     the seconds between 0-59.
 * @see     java.util.Calendar
 * @deprecated As of JDK version 1.1,
 * replaced by <code>Calendar.set(year + 1900, month, date,
 * hrs, min, sec)</code> or <code>GregorianCalendar(year + 1900,
 * month, date, hrs, min, sec)</code>.
 */
@Deprecated
public Date(int year, int month, int date, int hrs, int min, int sec) {
    int y = year + 1900;
    // month is 0-based. So we have to normalize month to support Long.MAX_VALUE.
    if (month >= 12) {
        y += month / 12;
        month %= 12;
    } else if (month < 0) {
        y += CalendarUtils.floorDivide(month, 12);
        month = CalendarUtils.mod(month, 12);
    }
    BaseCalendar cal = getCalendarSystem(y);
    cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.getDefaultRef());
    cdate.setNormalizedDate(y, month + 1, date).setTimeOfDay(hrs, min, sec, 0);
    getTimeImpl();
    cdate = null;
}
 
Example 15
Source File: Date.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Determines the date and time based on the arguments. The
 * arguments are interpreted as a year, month, day of the month,
 * hour of the day, minute within the hour, and second within the
 * minute, exactly as for the <tt>Date</tt> constructor with six
 * arguments, except that the arguments are interpreted relative
 * to UTC rather than to the local time zone. The time indicated is
 * returned represented as the distance, measured in milliseconds,
 * of that time from the epoch (00:00:00 GMT on January 1, 1970).
 *
 * @param   year    the year minus 1900.
 * @param   month   the month between 0-11.
 * @param   date    the day of the month between 1-31.
 * @param   hrs     the hours between 0-23.
 * @param   min     the minutes between 0-59.
 * @param   sec     the seconds between 0-59.
 * @return  the number of milliseconds since January 1, 1970, 00:00:00 GMT for
 *          the date and time specified by the arguments.
 * @see     java.util.Calendar
 * @deprecated As of JDK version 1.1,
 * replaced by <code>Calendar.set(year + 1900, month, date,
 * hrs, min, sec)</code> or <code>GregorianCalendar(year + 1900,
 * month, date, hrs, min, sec)</code>, using a UTC
 * <code>TimeZone</code>, followed by <code>Calendar.getTime().getTime()</code>.
 */
@Deprecated
public static long UTC(int year, int month, int date,
                       int hrs, int min, int sec) {
    int y = year + 1900;
    // month is 0-based. So we have to normalize month to support Long.MAX_VALUE.
    if (month >= 12) {
        y += month / 12;
        month %= 12;
    } else if (month < 0) {
        y += CalendarUtils.floorDivide(month, 12);
        month = CalendarUtils.mod(month, 12);
    }
    int m = month + 1;
    BaseCalendar cal = getCalendarSystem(y);
    BaseCalendar.Date udate = (BaseCalendar.Date) cal.newCalendarDate(null);
    udate.setNormalizedDate(y, m, date).setTimeOfDay(hrs, min, sec, 0);

    // Use a Date instance to perform normalization. Its fastTime
    // is the UTC value after the normalization.
    Date d = new Date(0);
    d.normalize(udate);
    return d.fastTime;
}
 
Example 16
Source File: Date.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Allocates a <code>Date</code> object and initializes it so that
 * it represents the instant at the start of the second specified
 * by the <code>year</code>, <code>month</code>, <code>date</code>,
 * <code>hrs</code>, <code>min</code>, and <code>sec</code> arguments,
 * in the local time zone.
 *
 * @param   year    the year minus 1900.
 * @param   month   the month between 0-11.
 * @param   date    the day of the month between 1-31.
 * @param   hrs     the hours between 0-23.
 * @param   min     the minutes between 0-59.
 * @param   sec     the seconds between 0-59.
 * @see     java.util.Calendar
 * @deprecated As of JDK version 1.1,
 * replaced by <code>Calendar.set(year + 1900, month, date,
 * hrs, min, sec)</code> or <code>GregorianCalendar(year + 1900,
 * month, date, hrs, min, sec)</code>.
 */
@Deprecated
public Date(int year, int month, int date, int hrs, int min, int sec) {
    int y = year + 1900;
    // month is 0-based. So we have to normalize month to support Long.MAX_VALUE.
    if (month >= 12) {
        y += month / 12;
        month %= 12;
    } else if (month < 0) {
        y += CalendarUtils.floorDivide(month, 12);
        month = CalendarUtils.mod(month, 12);
    }
    BaseCalendar cal = getCalendarSystem(y);
    cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.getDefaultRef());
    cdate.setNormalizedDate(y, month + 1, date).setTimeOfDay(hrs, min, sec, 0);
    getTimeImpl();
    cdate = null;
}
 
Example 17
Source File: Date.java    From jdk-1.7-annotated with Apache License 2.0 4 votes vote down vote up
/**
 * Allocates a <code>Date</code> object and initializes it so that
 * it represents the instant at the start of the second specified
 * by the <code>year</code>, <code>month</code>, <code>date</code>,
 * <code>hrs</code>, <code>min</code>, and <code>sec</code> arguments,
 * in the local time zone.
 *
 * @param   year    the year minus 1900.
 * @param   month   the month between 0-11.
 * @param   date    the day of the month between 1-31.
 * @param   hrs     the hours between 0-23.
 * @param   min     the minutes between 0-59.
 * @param   sec     the seconds between 0-59.
 * @see     java.util.Calendar
 * @deprecated As of JDK version 1.1,
 * replaced by <code>Calendar.set(year + 1900, month, date,
 * hrs, min, sec)</code> or <code>GregorianCalendar(year + 1900,
 * month, date, hrs, min, sec)</code>.
 */
@Deprecated
public Date(int year, int month, int date, int hrs, int min, int sec) {
    int y = year + 1900;
    // month is 0-based. So we have to normalize month to support Long.MAX_VALUE.
    if (month >= 12) {
        y += month / 12;
        month %= 12;
    } else if (month < 0) {
        y += CalendarUtils.floorDivide(month, 12);
        month = CalendarUtils.mod(month, 12);
    }
    BaseCalendar cal = getCalendarSystem(y);
    cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.getDefaultRef());
    cdate.setNormalizedDate(y, month + 1, date).setTimeOfDay(hrs, min, sec, 0);
    getTimeImpl();
    cdate = null;
}
 
Example 18
Source File: Date.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Allocates a <code>Date</code> object and initializes it so that
 * it represents the instant at the start of the second specified
 * by the <code>year</code>, <code>month</code>, <code>date</code>,
 * <code>hrs</code>, <code>min</code>, and <code>sec</code> arguments,
 * in the local time zone.
 *
 * @param   year    the year minus 1900.
 * @param   month   the month between 0-11.
 * @param   date    the day of the month between 1-31.
 * @param   hrs     the hours between 0-23.
 * @param   min     the minutes between 0-59.
 * @param   sec     the seconds between 0-59.
 * @see     java.util.Calendar
 * @deprecated As of JDK version 1.1,
 * replaced by <code>Calendar.set(year + 1900, month, date,
 * hrs, min, sec)</code> or <code>GregorianCalendar(year + 1900,
 * month, date, hrs, min, sec)</code>.
 */
@Deprecated
public Date(int year, int month, int date, int hrs, int min, int sec) {
    int y = year + 1900;
    // month is 0-based. So we have to normalize month to support Long.MAX_VALUE.
    if (month >= 12) {
        y += month / 12;
        month %= 12;
    } else if (month < 0) {
        y += CalendarUtils.floorDivide(month, 12);
        month = CalendarUtils.mod(month, 12);
    }
    BaseCalendar cal = getCalendarSystem(y);
    cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.getDefaultRef());
    cdate.setNormalizedDate(y, month + 1, date).setTimeOfDay(hrs, min, sec, 0);
    getTimeImpl();
    cdate = null;
}
 
Example 19
Source File: Date.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Determines the date and time based on the arguments. The
 * arguments are interpreted as a year, month, day of the month,
 * hour of the day, minute within the hour, and second within the
 * minute, exactly as for the <tt>Date</tt> constructor with six
 * arguments, except that the arguments are interpreted relative
 * to UTC rather than to the local time zone. The time indicated is
 * returned represented as the distance, measured in milliseconds,
 * of that time from the epoch (00:00:00 GMT on January 1, 1970).
 *
 * @param   year    the year minus 1900.
 * @param   month   the month between 0-11.
 * @param   date    the day of the month between 1-31.
 * @param   hrs     the hours between 0-23.
 * @param   min     the minutes between 0-59.
 * @param   sec     the seconds between 0-59.
 * @return  the number of milliseconds since January 1, 1970, 00:00:00 GMT for
 *          the date and time specified by the arguments.
 * @see     java.util.Calendar
 * @deprecated As of JDK version 1.1,
 * replaced by <code>Calendar.set(year + 1900, month, date,
 * hrs, min, sec)</code> or <code>GregorianCalendar(year + 1900,
 * month, date, hrs, min, sec)</code>, using a UTC
 * <code>TimeZone</code>, followed by <code>Calendar.getTime().getTime()</code>.
 */
@Deprecated
public static long UTC(int year, int month, int date,
                       int hrs, int min, int sec) {
    int y = year + 1900;
    // month is 0-based. So we have to normalize month to support Long.MAX_VALUE.
    if (month >= 12) {
        y += month / 12;
        month %= 12;
    } else if (month < 0) {
        y += CalendarUtils.floorDivide(month, 12);
        month = CalendarUtils.mod(month, 12);
    }
    int m = month + 1;
    BaseCalendar cal = getCalendarSystem(y);
    BaseCalendar.Date udate = (BaseCalendar.Date) cal.newCalendarDate(null);
    udate.setNormalizedDate(y, m, date).setTimeOfDay(hrs, min, sec, 0);

    // Use a Date instance to perform normalization. Its fastTime
    // is the UTC value after the normalization.
    Date d = new Date(0);
    d.normalize(udate);
    return d.fastTime;
}
 
Example 20
Source File: Date.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Allocates a <code>Date</code> object and initializes it so that
 * it represents the instant at the start of the second specified
 * by the <code>year</code>, <code>month</code>, <code>date</code>,
 * <code>hrs</code>, <code>min</code>, and <code>sec</code> arguments,
 * in the local time zone.
 *
 * @param   year    the year minus 1900.
 * @param   month   the month between 0-11.
 * @param   date    the day of the month between 1-31.
 * @param   hrs     the hours between 0-23.
 * @param   min     the minutes between 0-59.
 * @param   sec     the seconds between 0-59.
 * @see     java.util.Calendar
 * @deprecated As of JDK version 1.1,
 * replaced by <code>Calendar.set(year + 1900, month, date,
 * hrs, min, sec)</code> or <code>GregorianCalendar(year + 1900,
 * month, date, hrs, min, sec)</code>.
 */
@Deprecated
public Date(int year, int month, int date, int hrs, int min, int sec) {
    int y = year + 1900;
    // month is 0-based. So we have to normalize month to support Long.MAX_VALUE.
    if (month >= 12) {
        y += month / 12;
        month %= 12;
    } else if (month < 0) {
        y += CalendarUtils.floorDivide(month, 12);
        month = CalendarUtils.mod(month, 12);
    }
    BaseCalendar cal = getCalendarSystem(y);
    cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.getDefaultRef());
    cdate.setNormalizedDate(y, month + 1, date).setTimeOfDay(hrs, min, sec, 0);
    getTimeImpl();
    cdate = null;
}