gpt4 book ai didi

org.apache.xmlbeans.XmlCalendar类的使用及代码示例

转载 作者:知者 更新时间:2024-03-19 01:56:40 30 4
gpt4 key购买 nike

本文整理了Java中org.apache.xmlbeans.XmlCalendar类的一些代码示例,展示了XmlCalendar类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XmlCalendar类的具体详情如下:
包路径:org.apache.xmlbeans.XmlCalendar
类名称:XmlCalendar

XmlCalendar介绍

[英]An XML Schema compatible subclass of java.util.GregorianCalendar. XmlCalendar modifies several key details in the behavior of GregorianCalendar to make it more useful when dealing with XML dates.

It is easy to convert between XmlCalendar and GDate, or to parse or emit an XmlCalendar using a standard XML Schema lexical representation.

  1. To match XML Schema dates, this XmlCalendar is a fully proleptic Gregorian calendar by default, which means that Gregorian calendar rules are applied backwards in time as if they had always been in effect, actual historical circumstances concerning the observance of the 1582 decree of Pope Gregory XIII notwithstanding.
  2. In order to better support partially-specified dates for XML Schema, this implementation provides a stable get(field) method that does not modify the instance if you are acessing a field right after it was explicitly set: a set followed by a get will always return the same thing and will not fill in any other fields. However, if you get a field that was not explicitly set, then all the fields are still automatically filled and normalized for you, just like a regular GregorianCalendar. If you wish to force the completion and defaulting of all the fields (without hunting to get one that happens to be unset), you can always do so by calling getTime().
  3. When a year is unspecified and needs to be filled in automatically (for example when using a .get or .getTime method as discussed above), the year is defaulted to year 0 (also known as 1 BC). This is different from GregorianCalendar, which chooses 1970. The reason 0 is preferable is that it is a leap year and so it permits the date --2-29 to be specified stably. A different default year can be chosen via the static method #setDefaultYear(int), or by setting the system property "user.defaultyear". If you do change this value, you should pick another leap year such as 2000 and avoid non-leap years such as 1900.
  4. When constructing an XmlCalendar from an XML Schema formatted date or time string or GDate object, the timezone for the calendar is taken from the string if it is present, or taken to be java.util.TimeZone#getDefault() if not.

For example, the XML timezone "Z" is translated to "GMT"; the XML timezone "+05:00" is translated to "GMT+05:00".

  1. Finally, this implementation provides a String constructor and a toString() method that comply with the XML Schema conventions for formatting a date. If only a subset of fields have been explicitly set, toString() produces a string with the proper subset of information.
    [中]与XML模式兼容的java子类。util。格雷戈里安卡伦达。XmlCalendar修改了GregoriaCalendar行为中的几个关键细节,使其在处理XML日期时更加有用。
    很容易在XmlCalendar和GDate之间转换,或者使用标准的XML模式词法表示来解析或发出XmlCalendar。
    1.为了匹配XML模式日期,默认情况下,该XmlCalendar是一个完全提前的公历,这意味着公历规则在时间上向后应用,就好像它们一直有效一样,尽管存在与遵守教皇格雷戈里十三世1582法令有关的实际历史情况。
    1.为了更好地支持XML模式的部分指定日期,此实现提供了一个稳定的get(field)方法,如果在显式设置字段后立即访问该实例,则该方法不会修改该实例:后跟get的set将始终返回相同的内容,并且不会填充任何其他字段。但是,如果您得到一个未明确设置的字段,那么所有字段仍然会自动填充并为您进行规范化,就像常规的GregoriaCalendar一样。如果您希望强制完成和默认所有字段(而不需要寻找一个恰好未设置的字段),您可以通过调用getTime()来完成。
    1.当年份未指定且需要自动填写时(例如,当使用上面讨论的.get或.getTime方法时),年份默认为0年(也称为公元前1年)。这与选择1970年的格雷戈里安卡伦达不同。0更可取的原因是它是闰年,因此它允许稳定地指定日期--2-29。可以通过静态方法#setDefaultYear(int)或通过设置系统属性“user.defaultyear”来选择不同的默认年份。如果确实更改了此值,则应选择另一个闰年,如2000年,并避免非闰年,如1900年。
    1.从XML模式格式的日期或时间字符串或GDate对象构造XmlCalendar时,日历的时区取自字符串(如果存在),或者取自java。util。时区#getDefault()如果不是。
    例如,XML时区“Z”被翻译成“GMT”;XML时区“+05:00”被翻译为“GMT+05:00”。
    1.最后,这个实现提供了一个字符串构造函数和一个toString()方法,它们符合XML模式中格式化日期的约定。如果只显式设置了字段的子集,那么toString()将生成一个包含适当信息子集的字符串。

代码示例

代码示例来源:origin: org.apache.xmlbeans/xmlbeans

/**
 * Retrieves the value of the current time as an {@link XmlCalendar}.
 * <p>
 * {@link XmlCalendar} is a subclass of {@link java.util.GregorianCalendar}
 * which is slightly customized to match XML schema date rules.
 * <p>
 * The returned {@link XmlCalendar} has only those time and date fields
 * set that are reflected in the GDate object.  Because of the way the
 * {@link java.util.Calendar} contract works, any information in the isSet() vanishes
 * as soon as you view any unset field using get() methods.
 * This means that if it is important to understand which date fields
 * are set, you must call isSet() first before get().
 */
public XmlCalendar getCalendar()
{
  return new XmlCalendar(this);
}

代码示例来源:origin: org.apache.xmlbeans/xmlbeans

/**
 * Overrides GregorianCalendar.computeTime to apply a different
 * default year.  (It must be a leap year.)
 */ 
protected void computeTime()
{
  boolean unsetYear = !isSet(YEAR);
  if (unsetYear)
    set(YEAR, getDefaultYear());
  try
  {
    super.computeTime();
  }
  finally
  {
    if (unsetYear)
      clear(YEAR);
  }
}

代码示例来源:origin: org.apache.xmlbeans/xmlbeans

/**
 * Constructs an XmlCalendar from a Date.
 * 
 * The default TimeZone is used for computing the various fields.
 */
public XmlCalendar(Date date)
{
  this(TimeZone.getDefault(), new GDate(date));
  complete();
}

代码示例来源:origin: org.apache.xmlbeans/xmlbeans

/**
 * Constructs an empty instance with no fields set.
 */ 
public XmlCalendar()
{
  setGregorianChange(_beginningOfTime); // proleptic
  clear();
}

代码示例来源:origin: org.apache.xmlbeans/xmlbeans

/**
 * Gets the value for a given time field.
 * 
 * Unlike the GregorianCalendar implementation, the get() does not
 * force a complete of all fields.  If you wish to force a completion
 * of all the fields, call getTime() first.
 */
public int get(int field)
{
  if (!isSet(field) || isTimeSet)
    return super.get(field); // forces a complete
  else
    return internalGet(field); // does not force a complete.
}

代码示例来源:origin: org.apache.xmlbeans/xmlbeans

private XmlCalendar(TimeZone tz, GDateSpecification date)
  setGregorianChange(_beginningOfTime); // proleptic
  clear();
    if (y > 0)
      set(Calendar.ERA, GregorianCalendar.AD);
      set(Calendar.ERA, GregorianCalendar.BC);
    set(Calendar.YEAR, y);
    set(Calendar.MONTH, date.getMonth() - 1); // note!!
  if (date.hasDay())
    set(Calendar.DAY_OF_MONTH, date.getDay());
  if (date.hasTime())
    set(Calendar.HOUR_OF_DAY, date.getHour());
    set(Calendar.MINUTE, date.getMinute());
    set(Calendar.SECOND, date.getSecond());
    if (date.getFraction().scale() > 0)
      set(Calendar.MILLISECOND, date.getMillisecond());
    set(Calendar.ZONE_OFFSET, date.getTimeZoneSign() * 1000 * 60 * (date.getTimeZoneHour() * 60 + date.getTimeZoneMinute()));
    set(Calendar.DST_OFFSET, 0); // note!!  if we don't do this, then GregorianCalendar will pick up DST from the time zone

代码示例来源:origin: com.att.ajsc/ajsc-core

public static String getStartTimestamp(String epoch) {
  long stime = Long.parseLong((String) epoch);
  XmlCalendar cal = new XmlCalendar(new Date(stime));
  XMLGregorianCalendar initTime = null;
  try {
    initTime = DatatypeFactory.newInstance().newXMLGregorianCalendar(
        cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1,
        cal.get(Calendar.DAY_OF_MONTH),
        cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE),
        cal.get(Calendar.SECOND), cal.get(Calendar.MILLISECOND),
        Math.round(cal.get(Calendar.ZONE_OFFSET) / 1000 / 60));
  } catch (Exception ex) {
    initTime = null;
  }
  if (initTime == null)
    return null;
  else
    return initTime.toString();
}

代码示例来源:origin: org.apache.airavata/airavata-workflow-tracking

public static Date getActivityTimestamp(XmlObject activity) throws ParseException {
  // $ACTIVITY_XML/*/timestamp
  XmlCursor xc = activity.newCursor();
  // ./
  // xc.toStartDoc();
  // ./*
  xc.toNextToken();
  // ./*/timestamp
  xc.toChild(TIMESTAMP_QNAME);
  System.out.println(xc.xmlText());
  XmlCalendar calendar = new XmlCalendar(xc.getTextValue());
  // return getDateFormat().parse(xc.getTextValue()); // fixme: this
  // supports only one date format
  return calendar.getTime();
}

代码示例来源:origin: org.apache.xmlbeans/com.springsource.org.apache.xmlbeans

private XmlCalendar(TimeZone tz, GDateSpecification date)
  setGregorianChange(_beginningOfTime); // proleptic
  clear();
    if (y > 0)
      set(Calendar.ERA, GregorianCalendar.AD);
      set(Calendar.ERA, GregorianCalendar.BC);
    set(Calendar.YEAR, y);
    set(Calendar.MONTH, date.getMonth() - 1); // note!!
  if (date.hasDay())
    set(Calendar.DAY_OF_MONTH, date.getDay());
  if (date.hasTime())
    set(Calendar.HOUR_OF_DAY, date.getHour());
    set(Calendar.MINUTE, date.getMinute());
    set(Calendar.SECOND, date.getSecond());
    if (date.getFraction().scale() > 0)
      set(Calendar.MILLISECOND, date.getMillisecond());
    set(Calendar.ZONE_OFFSET, date.getTimeZoneSign() * 1000 * 60 * (date.getTimeZoneHour() * 60 + date.getTimeZoneMinute()));
    set(Calendar.DST_OFFSET, 0); // note!!  if we don't do this, then GregorianCalendar will pick up DST from the time zone

代码示例来源:origin: org.apache.xmlbeans/com.springsource.org.apache.xmlbeans

/**
 * Constructs an empty instance with no fields set.
 */ 
public XmlCalendar()
{
  setGregorianChange(_beginningOfTime); // proleptic
  clear();
}

代码示例来源:origin: org.apache.xmlbeans/com.springsource.org.apache.xmlbeans

/**
 * Gets the value for a given time field.
 * 
 * Unlike the GregorianCalendar implementation, the get() does not
 * force a complete of all fields.  If you wish to force a completion
 * of all the fields, call getTime() first.
 */
public int get(int field)
{
  if (!isSet(field) || isTimeSet)
    return super.get(field); // forces a complete
  else
    return internalGet(field); // does not force a complete.
}

代码示例来源:origin: org.apache.xmlbeans/com.springsource.org.apache.xmlbeans

/**
 * Overrides GregorianCalendar.computeTime to apply a different
 * default year.  (It must be a leap year.)
 */ 
protected void computeTime()
{
  boolean unsetYear = !isSet(YEAR);
  if (unsetYear)
    set(YEAR, getDefaultYear());
  try
  {
    super.computeTime();
  }
  finally
  {
    if (unsetYear)
      clear(YEAR);
  }
}

代码示例来源:origin: org.apache.xmlbeans/xmlbeans

/**
 * Retrieves the value of the current time as an {@link XmlCalendar}.
 * <p>
 * {@link XmlCalendar} is a subclass of {@link java.util.GregorianCalendar}
 * which is slightly customized to match XML schema date rules.
 * <p>
 * The returned {@link XmlCalendar} has only those time and date fields
 * set that are reflected in the GDate object.  Because of the way the
 * {@link java.util.Calendar} contract works, any information in the isSet() vanishes
 * as soon as you view any unset field using get() methods.
 * This means that if it is important to understand which date fields
 * are set, you must call isSet() first before get().
 */
public XmlCalendar getCalendar()
{
  return new XmlCalendar(this);
}

代码示例来源:origin: com.github.pjfanning/xmlbeans

private XmlCalendar(TimeZone tz, GDateSpecification date)
  setGregorianChange(_beginningOfTime); // proleptic
  clear();
    if (y > 0)
      set(Calendar.ERA, GregorianCalendar.AD);
      set(Calendar.ERA, GregorianCalendar.BC);
    set(Calendar.YEAR, y);
    set(Calendar.MONTH, date.getMonth() - 1); // note!!
  if (date.hasDay())
    set(Calendar.DAY_OF_MONTH, date.getDay());
  if (date.hasTime())
    set(Calendar.HOUR_OF_DAY, date.getHour());
    set(Calendar.MINUTE, date.getMinute());
    set(Calendar.SECOND, date.getSecond());
    if (date.getFraction().scale() > 0)
      set(Calendar.MILLISECOND, date.getMillisecond());
    set(Calendar.ZONE_OFFSET, date.getTimeZoneSign() * 1000 * 60 * (date.getTimeZoneHour() * 60 + date.getTimeZoneMinute()));
    set(Calendar.DST_OFFSET, 0); // note!!  if we don't do this, then GregorianCalendar will pick up DST from the time zone

代码示例来源:origin: com.github.pjfanning/xmlbeans

/**
 * Constructs an empty instance with no fields set.
 */ 
public XmlCalendar()
{
  setGregorianChange(_beginningOfTime); // proleptic
  clear();
}

代码示例来源:origin: com.github.pjfanning/xmlbeans

/**
 * Gets the value for a given time field.
 * 
 * Unlike the GregorianCalendar implementation, the get() does not
 * force a complete of all fields.  If you wish to force a completion
 * of all the fields, call getTime() first.
 */
public int get(int field)
{
  if (!isSet(field) || isTimeSet)
    return super.get(field); // forces a complete
  else
    return internalGet(field); // does not force a complete.
}

代码示例来源:origin: com.github.pjfanning/xmlbeans

/**
 * Constructs an XmlCalendar from a Date.
 * 
 * The default TimeZone is used for computing the various fields.
 */
public XmlCalendar(Date date)
{
  this(TimeZone.getDefault(), new GDate(date));
  complete();
}

代码示例来源:origin: com.github.pjfanning/xmlbeans

/**
 * Overrides GregorianCalendar.computeTime to apply a different
 * default year.  (It must be a leap year.)
 */ 
protected void computeTime()
{
  boolean unsetYear = !isSet(YEAR);
  if (unsetYear)
    set(YEAR, getDefaultYear());
  try
  {
    super.computeTime();
  }
  finally
  {
    if (unsetYear)
      clear(YEAR);
  }
}

代码示例来源:origin: org.apache.xmlbeans/xmlbeans

writer.println("<p>Run on " + (new XmlCalendar(new Date())) + "</p>");
writer.println("<p>Values in schema or instance valid columns are results from compiling or validating respectively.");
writer.println("Red or orange background mean the test failed.</p>");

代码示例来源:origin: org.apache.xmlbeans/com.springsource.org.apache.xmlbeans

/**
 * Constructs an XmlCalendar from a Date.
 * 
 * The default TimeZone is used for computing the various fields.
 */
public XmlCalendar(Date date)
{
  this(TimeZone.getDefault(), new GDate(date));
  complete();
}

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com