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


Java GregorianCalendar.BC属性代码示例

本文整理汇总了Java中java.util.GregorianCalendar.BC属性的典型用法代码示例。如果您正苦于以下问题:Java GregorianCalendar.BC属性的具体用法?Java GregorianCalendar.BC怎么用?Java GregorianCalendar.BC使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.util.GregorianCalendar的用法示例。


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

示例1: next

@Override
public Timestamp next() {
  cal.clear();
  cal.set(Calendar.YEAR, MIN_YEAR + rng.nextInt(MAX_YEAR - MIN_YEAR + 1));
  cal.set(Calendar.DAY_OF_YEAR, 1 + rng.nextInt(cal
      .getActualMaximum(Calendar.DAY_OF_YEAR)));
  cal.set(Calendar.HOUR_OF_DAY, rng.nextInt(24));
  cal.set(Calendar.MINUTE, rng.nextInt(60));
  cal.set(Calendar.SECOND, rng.nextInt(
      cal.getActualMaximum(Calendar.SECOND)));
  // Workaround for oracle jdbc bugs related to BC leap years
  if (cal.get(Calendar.ERA) == GregorianCalendar.BC
    && cal.get(Calendar.MONTH) == 1 && cal.get(Calendar.DAY_OF_MONTH) >= 28) {
    return next();
  }
  Timestamp timestamp = new Timestamp(cal.getTimeInMillis());
  if (precision > 0) {
    int nanos = rng.nextInt((int) Math.pow(10, precision));
    timestamp.setNanos(nanos * (int) Math.pow(10, NANOS_DIGITS - precision));
  }
  return timestamp;
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:22,代码来源:TimestampGenerator.java

示例2: Test4149677

/**
 * Reported bug is that a GregorianCalendar with a cutover of Date(Long.MAX_VALUE)
 * doesn't behave as a pure Julian calendar.
 * CANNOT REPRODUCE THIS BUG
 */
public void Test4149677() {
    TimeZone[] zones = {TimeZone.getTimeZone("GMT"),
        TimeZone.getTimeZone("PST"),
        TimeZone.getTimeZone("EAT")};
    for (int i = 0; i < zones.length; ++i) {
        GregorianCalendar calendar = new GregorianCalendar(zones[i]);

        // Make sure extreme values don't wrap around
        calendar.setTime(new Date(Long.MIN_VALUE));
        if (calendar.get(ERA) != GregorianCalendar.BC) {
            errln("Fail: Date(Long.MIN_VALUE) has an AD year in " + zones[i]);
        }
        calendar.setTime(new Date(Long.MAX_VALUE));
        if (calendar.get(ERA) != GregorianCalendar.AD) {
            errln("Fail: Date(Long.MAX_VALUE) has a BC year in " + zones[i]);
        }

        calendar.setGregorianChange(new Date(Long.MAX_VALUE));
        // to obtain a pure Julian calendar

        boolean is100Leap = calendar.isLeapYear(100);
        if (!is100Leap) {
            errln("test failed with zone " + zones[i].getID());
            errln(" cutover date is Date(Long.MAX_VALUE)");
            errln(" isLeapYear(100) returns: " + is100Leap);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:CalendarRegression.java

示例3: XMLGregorianCalendarImpl

/**
     * <p>Convert a <code>java.util.GregorianCalendar</code> to XML Schema 1.0
     * representation.</p>
     *
     * <table border="2" rules="all" cellpadding="2">
     *   <thead>
     *     <tr>
     *       <th align="center" colspan="2">
     *          Field by Field Conversion from
     *          <code>java.util.GregorianCalendar</code> to this class
     *       </th>
     *     </tr>
     *   </thead>
     *   <tbody>
     *     <tr>
     *        <th><code>javax.xml.datatype.XMLGregorianCalendar</code> field</th>
     *        <th><code>java.util.GregorianCalendar</code> field</th>
     *     </tr>
     *     <tr>
     *       <th>{@link #setYear(int)}</th>
     *       <th><code>ERA == GregorianCalendar.BC ? -YEAR : YEAR</code></th>
     *     </tr>
     *     <tr>
     *       <th>{@link #setMonth(int)}</th>
     *       <th><code>MONTH + 1</code></th>
     *     </tr>
     *     <tr>
     *       <th>{@link #setDay(int)}</th>
     *       <th><code>DAY_OF_MONTH</code></th>
     *     </tr>
     *     <tr>
     *       <th>{@link #setTime(int,int,int, BigDecimal)}</th>
     *       <th><code>HOUR_OF_DAY, MINUTE, SECOND, MILLISECOND</code></th>
     *     </tr>
     *     <tr>
     *       <th>{@link #setTimezone(int)}<i>*</i></th>
     *       <th><code>(ZONE_OFFSET + DST_OFFSET) / (60*1000)</code><br/>
     *       <i>(in minutes)</i>
     *       </th>
     *     </tr>
     *   </tbody>
     * </table>
     * <p><i>*</i>conversion loss of information. It is not possible to represent
     * a <code>java.util.GregorianCalendar</code> daylight savings timezone id in the
     * XML Schema 1.0 date/time datatype representation.</p>
     *
     * <p>To compute the return value's <code>TimeZone</code> field,
     * <ul>
     * <li>when <code>this.getTimezone() != DatatypeConstants.FIELD_UNDEFINED</code>,
     * create a <code>java.util.TimeZone</code> with a custom timezone id
     * using the <code>this.getTimezone()</code>.</li>
     * <li>else use the <code>GregorianCalendar</code> default timezone value
     * for the host is defined as specified by
     * <code>java.util.TimeZone.getDefault()</code>.</li></p>
     *
     * @param cal <code>java.util.GregorianCalendar</code> used to create <code>XMLGregorianCalendar</code>
     */
public XMLGregorianCalendarImpl(GregorianCalendar cal) {

    int year = cal.get(Calendar.YEAR);
    if (cal.get(Calendar.ERA) == GregorianCalendar.BC) {
        year = -year;
    }
    this.setYear(year);

    // Calendar.MONTH is zero based, XSD Date datatype's month field starts
    // with JANUARY as 1.
    this.setMonth(cal.get(Calendar.MONTH) + 1);
    this.setDay(cal.get(Calendar.DAY_OF_MONTH));
    this.setTime(
            cal.get(Calendar.HOUR_OF_DAY),
            cal.get(Calendar.MINUTE),
            cal.get(Calendar.SECOND),
            cal.get(Calendar.MILLISECOND));

    // Calendar ZONE_OFFSET and DST_OFFSET fields are in milliseconds.
    int offsetInMinutes = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / (60 * 1000);
    this.setTimezone(offsetInMinutes);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:79,代码来源:XMLGregorianCalendarImpl.java

示例4: XMLGregorianCalendarImpl

/**
     * <p>Convert a <code>java.util.GregorianCalendar</code> to XML Schema 1.0
     * representation.</p>
     *
     * <table border="2" rules="all" cellpadding="2">
     *   <thead>
     *     <tr>
     *       <th align="center" colspan="2">
     *          Field by Field Conversion from
     *          <code>java.util.GregorianCalendar</code> to this class
     *       </th>
     *     </tr>
     *   </thead>
     *   <tbody>
     *     <tr>
     *        <th><code>javax.xml.datatype.XMLGregorianCalendar</code> field</th>
     *        <th><code>java.util.GregorianCalendar</code> field</th>
     *     </tr>
     *     <tr>
     *       <th>{@link #setYear(int)}</th>
     *       <th><code>ERA == GregorianCalendar.BC ? -YEAR : YEAR</code></th>
     *     </tr>
     *     <tr>
     *       <th>{@link #setMonth(int)}</th>
     *       <th><code>MONTH + 1</code></th>
     *     </tr>
     *     <tr>
     *       <th>{@link #setDay(int)}</th>
     *       <th><code>DAY_OF_MONTH</code></th>
     *     </tr>
     *     <tr>
     *       <th>{@link #setTime(int,int,int, BigDecimal)}</th>
     *       <th><code>HOUR_OF_DAY, MINUTE, SECOND, MILLISECOND</code></th>
     *     </tr>
     *     <tr>
     *       <th>{@link #setTimezone(int)}<i>*</i></th>
     *       <th><code>(ZONE_OFFSET + DST_OFFSET) / (60*1000)</code><br/>
     *       <i>(in minutes)</i>
     *       </th>
     *     </tr>
     *   </tbody>
     * </table>
     * <p><i>*</i>conversion loss of information. It is not possible to represent
     * a <code>java.util.GregorianCalendar</code> daylight savings timezone id in the
     * XML Schema 1.0 date/time datatype representation.</p>
     *
     * <p>To compute the return value's <code>TimeZone</code> field,
     * <ul>
     * <li>when <code>this.getTimezone() != DatatypeConstants.FIELD_UNDEFINED</code>,
     * create a <code>java.util.TimeZone</code> with a custom timezone id
     * using the <code>this.getTimezone()</code>.</li>
     * <li>else use the <code>GregorianCalendar</code> default timezone value
     * for the host is defined as specified by
     * <code>java.util.TimeZone.getDefault()</code>.</li></p>
     *
     * @param cal <code>java.util.GregorianCalendar</code> used to create <code>XMLGregorianCalendar</code>
     */
public XMLGregorianCalendarImpl(GregorianCalendar cal) {

    int year1 = cal.get(Calendar.YEAR);
    if (cal.get(Calendar.ERA) == GregorianCalendar.BC) {
        year1 = -year1;
    }
    this.setYear(year1);

    // Calendar.MONTH is zero based, XSD Date datatype's month field starts
    // with JANUARY as 1.
    this.setMonth(cal.get(Calendar.MONTH) + 1);
    this.setDay(cal.get(Calendar.DAY_OF_MONTH));
    this.setTime(
            cal.get(Calendar.HOUR_OF_DAY),
            cal.get(Calendar.MINUTE),
            cal.get(Calendar.SECOND),
            cal.get(Calendar.MILLISECOND));

    // Calendar ZONE_OFFSET and DST_OFFSET fields are in milliseconds.
    int offsetInMinutes = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / (60 * 1000);
    this.setTimezone(offsetInMinutes);
    save();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:80,代码来源:XMLGregorianCalendarImpl.java


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