当前位置: 首页>>代码示例>>Java>>正文


Java CalendarUtils类代码示例

本文整理汇总了Java中sun.util.calendar.CalendarUtils的典型用法代码示例。如果您正苦于以下问题:Java CalendarUtils类的具体用法?Java CalendarUtils怎么用?Java CalendarUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CalendarUtils类属于sun.util.calendar包,在下文中一共展示了CalendarUtils类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setMonth

import sun.util.calendar.CalendarUtils; //导入依赖的package包/类
/**
 * Sets the month of this date to the specified value. This
 * <tt>Date</tt> object is modified so that it represents a point
 * in time within the specified month, with the year, date, hour,
 * minute, and second the same as before, as interpreted in the
 * local time zone. If the date was October 31, for example, and
 * the month is set to June, then the new date will be treated as
 * if it were on July 1, because June has only 30 days.
 *
 * @param   month   the month value between 0-11.
 * @see     java.util.Calendar
 * @deprecated As of JDK version 1.1,
 * replaced by <code>Calendar.set(Calendar.MONTH, int month)</code>.
 */
@Deprecated
public void setMonth(int month) {
    int y = 0;
    if (month >= 12) {
        y = month / 12;
        month %= 12;
    } else if (month < 0) {
        y = CalendarUtils.floorDivide(month, 12);
        month = CalendarUtils.mod(month, 12);
    }
    BaseCalendar.Date d = getCalendarDate();
    if (y != 0) {
        d.setNormalizedYear(d.getNormalizedYear() + y);
    }
    d.setMonth(month + 1); // adjust 0-based to 1-based month numbering
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:Date.java

示例2: setMonth

import sun.util.calendar.CalendarUtils; //导入依赖的package包/类
/**
 * Sets the month of this date to the specified value. This
 * {@code Date} object is modified so that it represents a point
 * in time within the specified month, with the year, date, hour,
 * minute, and second the same as before, as interpreted in the
 * local time zone. If the date was October 31, for example, and
 * the month is set to June, then the new date will be treated as
 * if it were on July 1, because June has only 30 days.
 *
 * @param   month   the month value between 0-11.
 * @see     java.util.Calendar
 * @deprecated As of JDK version 1.1,
 * replaced by {@code Calendar.set(Calendar.MONTH, int month)}.
 */
@Deprecated
public void setMonth(int month) {
    int y = 0;
    if (month >= 12) {
        y = month / 12;
        month %= 12;
    } else if (month < 0) {
        y = CalendarUtils.floorDivide(month, 12);
        month = CalendarUtils.mod(month, 12);
    }
    BaseCalendar.Date d = getCalendarDate();
    if (y != 0) {
        d.setNormalizedYear(d.getNormalizedYear() + y);
    }
    d.setMonth(month + 1); // adjust 0-based to 1-based month numbering
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:Date.java

示例3: setMonth

import sun.util.calendar.CalendarUtils; //导入依赖的package包/类
/**
    * Sets the month of this date to the specified value. This 
    * <tt>Date</tt> object is modified so that it represents a point 
    * in time within the specified month, with the year, date, hour, 
    * minute, and second the same as before, as interpreted in the 
    * local time zone. If the date was October 31, for example, and 
    * the month is set to June, then the new date will be treated as 
    * if it were on July 1, because June has only 30 days.
    *
    * @param   month   the month value between 0-11.
    * @see     java.util.Calendar
    * @deprecated As of JDK version 1.1,
    * replaced by <code>Calendar.set(Calendar.MONTH, int month)</code>.
    */
   @Deprecated
   public void setMonth(int month) {
int y = 0;
if (month >= 12) {
    y = month / 12;
    month %= 12;
} else if (month < 0) {
    y = CalendarUtils.floorDivide(month, 12);
    month = CalendarUtils.mod(month, 12);
}
       BaseCalendar.Date d = getCalendarDate();
if (y != 0) {
    d.setNormalizedYear(d.getNormalizedYear() + y);
}
d.setMonth(month + 1); // adjust 0-based to 1-based month numbering
   }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:31,代码来源:Date.java

示例4: setGregorianChange

import sun.util.calendar.CalendarUtils; //导入依赖的package包/类
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();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:GregorianCalendar.java

示例5: setGregorianChange

import sun.util.calendar.CalendarUtils; //导入依赖的package包/类
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 jcal = getJulianCalendarSystem();
d = (BaseCalendar.Date) jcal.newCalendarDate(TimeZone.NO_TIMEZONE);
jcal.getCalendarDateFromFixedDate(d, gregorianCutoverDate - 1);
gregorianCutoverYearJulian = d.getNormalizedYear();

if (time < gregorianCutover) {
    // The field values are no longer valid under the new
    // cutover date.
    setUnnormalized();
}
   }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:31,代码来源:GregorianCalendar.java

示例6: setGregorianChange

import sun.util.calendar.CalendarUtils; //导入依赖的package包/类
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 jcal = getJulianCalendarSystem();
    d = (BaseCalendar.Date) jcal.newCalendarDate(TimeZone.NO_TIMEZONE);
    jcal.getCalendarDateFromFixedDate(d, gregorianCutoverDate - 1);
    gregorianCutoverYearJulian = d.getNormalizedYear();

    if (time < gregorianCutover) {
        // The field values are no longer valid under the new
        // cutover date.
        setUnnormalized();
    }
}
 
开发者ID:ZhaoX,项目名称:jdk-1.7-annotated,代码行数:31,代码来源:GregorianCalendar.java

示例7: Date

import sun.util.calendar.CalendarUtils; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:Date.java

示例8: UTC

import sun.util.calendar.CalendarUtils; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:49,代码来源:Date.java

示例9: toString

import sun.util.calendar.CalendarUtils; //导入依赖的package包/类
/**
 * Converts this <code>Date</code> object to a <code>String</code>
 * of the form:
 * <blockquote><pre>
 * dow mon dd hh:mm:ss zzz yyyy</pre></blockquote>
 * where:<ul>
 * <li><tt>dow</tt> is the day of the week (<tt>Sun, Mon, Tue, Wed,
 *     Thu, Fri, Sat</tt>).
 * <li><tt>mon</tt> is the month (<tt>Jan, Feb, Mar, Apr, May, Jun,
 *     Jul, Aug, Sep, Oct, Nov, Dec</tt>).
 * <li><tt>dd</tt> is the day of the month (<tt>01</tt> through
 *     <tt>31</tt>), as two decimal digits.
 * <li><tt>hh</tt> is the hour of the day (<tt>00</tt> through
 *     <tt>23</tt>), as two decimal digits.
 * <li><tt>mm</tt> is the minute within the hour (<tt>00</tt> through
 *     <tt>59</tt>), as two decimal digits.
 * <li><tt>ss</tt> is the second within the minute (<tt>00</tt> through
 *     <tt>61</tt>, as two decimal digits.
 * <li><tt>zzz</tt> is the time zone (and may reflect daylight saving
 *     time). Standard time zone abbreviations include those
 *     recognized by the method <tt>parse</tt>. If time zone
 *     information is not available, then <tt>zzz</tt> is empty -
 *     that is, it consists of no characters at all.
 * <li><tt>yyyy</tt> is the year, as four decimal digits.
 * </ul>
 *
 * @return  a string representation of this date.
 * @see     java.util.Date#toLocaleString()
 * @see     java.util.Date#toGMTString()
 */
public String toString() {
    // "EEE MMM dd HH:mm:ss zzz yyyy";
    BaseCalendar.Date date = normalize();
    StringBuilder sb = new StringBuilder(28);
    int index = date.getDayOfWeek();
    if (index == BaseCalendar.SUNDAY) {
        index = 8;
    }
    convertToAbbr(sb, wtb[index]).append(' ');                        // EEE
    convertToAbbr(sb, wtb[date.getMonth() - 1 + 2 + 7]).append(' ');  // MMM
    CalendarUtils.sprintf0d(sb, date.getDayOfMonth(), 2).append(' '); // dd

    CalendarUtils.sprintf0d(sb, date.getHours(), 2).append(':');   // HH
    CalendarUtils.sprintf0d(sb, date.getMinutes(), 2).append(':'); // mm
    CalendarUtils.sprintf0d(sb, date.getSeconds(), 2).append(' '); // ss
    TimeZone zi = date.getZone();
    if (zi != null) {
        sb.append(zi.getDisplayName(date.isDaylightTime(), TimeZone.SHORT, Locale.US)); // zzz
    } else {
        sb.append("GMT");
    }
    sb.append(' ').append(date.getYear());  // yyyy
    return sb.toString();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:55,代码来源:Date.java

示例10: toGMTString

import sun.util.calendar.CalendarUtils; //导入依赖的package包/类
/**
 * Creates a string representation of this <tt>Date</tt> object of
 * the form:
 * <blockquote><pre>
 * d mon yyyy hh:mm:ss GMT</pre></blockquote>
 * where:<ul>
 * <li><i>d</i> is the day of the month (<tt>1</tt> through <tt>31</tt>),
 *     as one or two decimal digits.
 * <li><i>mon</i> is the month (<tt>Jan, Feb, Mar, Apr, May, Jun, Jul,
 *     Aug, Sep, Oct, Nov, Dec</tt>).
 * <li><i>yyyy</i> is the year, as four decimal digits.
 * <li><i>hh</i> is the hour of the day (<tt>00</tt> through <tt>23</tt>),
 *     as two decimal digits.
 * <li><i>mm</i> is the minute within the hour (<tt>00</tt> through
 *     <tt>59</tt>), as two decimal digits.
 * <li><i>ss</i> is the second within the minute (<tt>00</tt> through
 *     <tt>61</tt>), as two decimal digits.
 * <li><i>GMT</i> is exactly the ASCII letters "<tt>GMT</tt>" to indicate
 *     Greenwich Mean Time.
 * </ul><p>
 * The result does not depend on the local time zone.
 *
 * @return  a string representation of this date, using the Internet GMT
 *          conventions.
 * @see     java.text.DateFormat
 * @see     java.util.Date#toString()
 * @see     java.util.Date#toLocaleString()
 * @deprecated As of JDK version 1.1,
 * replaced by <code>DateFormat.format(Date date)</code>, using a
 * GMT <code>TimeZone</code>.
 */
@Deprecated
public String toGMTString() {
    // d MMM yyyy HH:mm:ss 'GMT'
    long t = getTime();
    BaseCalendar cal = getCalendarSystem(t);
    BaseCalendar.Date date =
        (BaseCalendar.Date) cal.getCalendarDate(getTime(), (TimeZone)null);
    StringBuilder sb = new StringBuilder(32);
    CalendarUtils.sprintf0d(sb, date.getDayOfMonth(), 1).append(' '); // d
    convertToAbbr(sb, wtb[date.getMonth() - 1 + 2 + 7]).append(' ');  // MMM
    sb.append(date.getYear()).append(' ');                            // yyyy
    CalendarUtils.sprintf0d(sb, date.getHours(), 2).append(':');      // HH
    CalendarUtils.sprintf0d(sb, date.getMinutes(), 2).append(':');    // mm
    CalendarUtils.sprintf0d(sb, date.getSeconds(), 2);                // ss
    sb.append(" GMT");                                                // ' GMT'
    return sb.toString();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:49,代码来源:Date.java


注:本文中的sun.util.calendar.CalendarUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。