java.util.Calendar.isSet()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(168)

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

Calendar.isSet介绍

[英]Whether the corresponding element in field[] has been set. Initially, these are all false. The first time the fields are computed, these are set to true and remain set even if the data becomes stale: you must check areFieldsSet if you want to know whether the value is up-to-date. Note that isSet is not a safe alternative to accessing this array directly, and will likewise return stale data! The array length is always FIELD_COUNT.
[中]是否已设置字段[]中的对应元素。起初,这些都是错误的。第一次计算字段时,这些字段被设置为true,即使数据过时也保持设置状态:如果要知道值是否为最新值,必须检查arefieldset。请注意,isSet不是直接访问此阵列的安全替代方案,它同样会返回陈旧数据!数组长度始终为字段计数。

代码示例

代码示例来源:origin: javax.xml.bind/jaxb-api

private static void formatSeconds(Calendar cal, StringBuilder buf) {
  formatTwoDigits(cal.get(Calendar.SECOND), buf);
  if (cal.isSet(Calendar.MILLISECOND)) { // milliseconds
    int n = cal.get(Calendar.MILLISECOND);
    if (n != 0) {
      String ms = Integer.toString(n);
      while (ms.length() < 3) {
        ms = '0' + ms; // left 0 paddings.
      }
      buf.append('.');
      buf.append(ms);
    }
  }
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

private static void formatSeconds(Calendar cal, StringBuilder buf) {
  formatTwoDigits(cal.get(Calendar.SECOND), buf);
  if (cal.isSet(Calendar.MILLISECOND)) { // milliseconds
    int n = cal.get(Calendar.MILLISECOND);
    if (n != 0) {
      String ms = Integer.toString(n);
      while (ms.length() < 3) {
        ms = '0' + ms; // left 0 paddings.
      }
      buf.append('.');
      buf.append(ms);
    }
  }
}

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

private static void formatSeconds(Calendar cal, StringBuilder buf) {
  formatTwoDigits(cal.get(Calendar.SECOND),buf);
  if (cal.isSet(Calendar.MILLISECOND)) { // milliseconds
    int n = cal.get(Calendar.MILLISECOND);
    if(n!=0) {
      String ms = Integer.toString(n);
      while (ms.length() < 3)
        ms = '0' + ms; // left 0 paddings.
      buf.append('.');
      buf.append(ms);
    }
  }
}

代码示例来源:origin: amzn/ion-java

if (cal.isSet(Calendar.MILLISECOND) || cal.isSet(Calendar.SECOND)) {
  precision = Precision.SECOND;
else if (cal.isSet(Calendar.HOUR_OF_DAY) || cal.isSet(Calendar.MINUTE)) {
  precision = Precision.MINUTE;
else if (cal.isSet(Calendar.DAY_OF_MONTH)) {
  precision = Precision.DAY;
else if (cal.isSet(Calendar.MONTH)) {
  precision = Precision.MONTH;
else if (cal.isSet(Calendar.YEAR)) {
  precision = Precision.YEAR;

代码示例来源:origin: org.glassfish.jaxb/jaxb-runtime

private static void formatSeconds(Calendar cal, StringBuilder buf) {
  formatTwoDigits(cal.get(Calendar.SECOND), buf);
  if (cal.isSet(Calendar.MILLISECOND)) { // milliseconds
    int n = cal.get(Calendar.MILLISECOND);
    if (n != 0) {
      String ms = Integer.toString(n);
      while (ms.length() < 3) {
        ms = '0' + ms; // left 0 paddings.
      }
      buf.append('.');
      buf.append(ms);
    }
  }
}

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

boolean isSetYear = calendar.isSet(Calendar.YEAR);
boolean isSetEra = calendar.isSet(Calendar.ERA);
boolean isSetMonth = calendar.isSet(Calendar.MONTH);
boolean isSetDay = calendar.isSet(Calendar.DAY_OF_MONTH);
boolean isSetHourOfDay = calendar.isSet(Calendar.HOUR_OF_DAY);
boolean isSetHour = calendar.isSet(Calendar.HOUR);
boolean isSetAmPm = calendar.isSet(Calendar.AM_PM);
boolean isSetMinute = calendar.isSet(Calendar.MINUTE);
boolean isSetSecond = calendar.isSet(Calendar.SECOND);
boolean isSetMillis = calendar.isSet(Calendar.MILLISECOND);
boolean isSetZone = calendar.isSet(Calendar.ZONE_OFFSET);
boolean isSetDst = calendar.isSet(Calendar.DST_OFFSET);

代码示例来源:origin: amzn/ion-java

boolean calendarHasMilliseconds = _calendar.isSet(Calendar.MILLISECOND);
    if (setLocalOffset)
      if (_calendar.isSet(Calendar.DST_OFFSET)) {
        offset += _calendar.get(Calendar.DST_OFFSET);

代码示例来源:origin: commons-net/commons-net

if (timestamp.isSet(Calendar.HOUR_OF_DAY)) {
  fmt.format(" %1$tH", timestamp);
  if (timestamp.isSet(Calendar.MINUTE)) {
    fmt.format(":%1$tM", timestamp);
    if (timestamp.isSet(Calendar.SECOND)) {
      fmt.format(":%1$tS", timestamp);
      if (timestamp.isSet(Calendar.MILLISECOND)) {
        fmt.format(".%1$tL", timestamp);

代码示例来源:origin: asakusafw/asakusafw

private void fillZeroIfUnset(Calendar calendar, int field) {
    assert calendar != null;
    if (calendar.isSet(field) == false) {
      calendar.set(field, 0);
    }
  }
}

代码示例来源:origin: mlykotom/valifi

/**
 * Checking for specific type if value is empty.
 * Used for checking if empty is allowed.
 *
 * @param actualValue value when checking
 * @return true when value is empty, false when values is not empty (e.g for String, use isEmpty())
 * @see #mCallback
 */
@Override
protected boolean whenThisFieldIsEmpty(@NonNull Calendar actualValue) {
  return !actualValue.isSet(Calendar.YEAR);    // TODO maybe check other values
}

代码示例来源:origin: asakusafw/asakusafw

private void fillZeroIfUnset(Calendar calendar, int field) {
  assert calendar != null;
  if (calendar.isSet(field) == false) {
    calendar.set(field, 0);
  }
}

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core

private String stringFromCalendar(Calendar sourceCalendar) {
  if (!(sourceCalendar.isSet(Calendar.HOUR) || sourceCalendar.isSet(Calendar.MINUTE) || sourceCalendar.isSet(Calendar.SECOND) || sourceCalendar.isSet(Calendar.MILLISECOND))) {
    return stringFromCalendar(sourceCalendar, Constants.DATE_QNAME);
  } else if (!(sourceCalendar.isSet(Calendar.YEAR) || sourceCalendar.isSet(Calendar.MONTH) || sourceCalendar.isSet(Calendar.DATE))) {
    return stringFromCalendar(sourceCalendar, Constants.TIME_QNAME);
  } else {
    return stringFromCalendar(sourceCalendar, Constants.DATE_TIME_QNAME);
  }
}

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

private String stringFromCalendar(Calendar sourceCalendar) {
  if (!(sourceCalendar.isSet(Calendar.HOUR) || sourceCalendar.isSet(Calendar.MINUTE) || sourceCalendar.isSet(Calendar.SECOND) || sourceCalendar.isSet(Calendar.MILLISECOND))) {
    return stringFromCalendar(sourceCalendar, Constants.DATE_QNAME);
  } else if (!(sourceCalendar.isSet(Calendar.YEAR) || sourceCalendar.isSet(Calendar.MONTH) || sourceCalendar.isSet(Calendar.DATE))) {
    return stringFromCalendar(sourceCalendar, Constants.TIME_QNAME);
  } else {
    return stringFromCalendar(sourceCalendar, Constants.DATE_TIME_QNAME);
  }
}

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

private String stringFromCalendar(Calendar sourceCalendar) {
  if (!(sourceCalendar.isSet(Calendar.HOUR) || sourceCalendar.isSet(Calendar.MINUTE) || sourceCalendar.isSet(Calendar.SECOND) || sourceCalendar.isSet(Calendar.MILLISECOND))) {
    return stringFromCalendar(sourceCalendar, XMLConstants.DATE_QNAME);
  } else if (!(sourceCalendar.isSet(Calendar.YEAR) || sourceCalendar.isSet(Calendar.MONTH) || sourceCalendar.isSet(Calendar.DATE))) {
    return stringFromCalendar(sourceCalendar, XMLConstants.TIME_QNAME);
  } else {
    return stringFromDate(sourceCalendar.getTime());
  }
}

代码示例来源:origin: com.att.research.xacml/xacml

private void validateDate() {
  this.calendar.getTime();
  int year	= this.calendar.get(Calendar.YEAR);
  if (this.calendar.isSet(Calendar.ERA) && this.calendar.get(Calendar.ERA) == GregorianCalendar.BC) {
    year    = 0 - year + 1;
  }
}

代码示例来源:origin: att/XACML

private void validateDate() {
  this.calendar.getTime();
  int year	= this.calendar.get(Calendar.YEAR);
  if (this.calendar.isSet(Calendar.ERA) && this.calendar.get(Calendar.ERA) == GregorianCalendar.BC) {
    year    = 0 - year + 1;
  }
}

代码示例来源:origin: at.bestsolution.eclipse/com.ibm.icu.base

/**
 * Determines if the given time field has a value set.
 * @return true if the given time field has a value set; false otherwise.
 * @stable ICU 2.0
 */
public final boolean isSet(int field)
{
  return calendar.isSet(getJDKField(field));
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/com.ibm.icu.base

/**
 * Determines if the given time field has a value set.
 * @return true if the given time field has a value set; false otherwise.
 * @stable ICU 2.0
 */
public final boolean isSet(int field)
{
  return calendar.isSet(getJDKField(field));
}

代码示例来源:origin: org.eclipse/yasson

@Override
protected String formatDefault(Calendar value, Locale locale) {
  DateTimeFormatter formatter = value.isSet(Calendar.HOUR) || value.isSet(Calendar.HOUR_OF_DAY) ?
      DateTimeFormatter.ISO_DATE_TIME : DateTimeFormatter.ISO_DATE;
  return formatter.withZone(value.getTimeZone().toZoneId())
      .withLocale(locale).format(toTemporalAccessor(value));
}

代码示例来源:origin: EvoSuite/evosuite

public final boolean isSet_final(int field)
{
  Capturer.capture(Instrumenter.CAPTURE_ID_JAVA_UTIL_CALENDAR, this, "isSet", "(I)Z", new Object[] {field});
  boolean ret = wrappedCalendar.isSet(field);
  Capturer.enable(Instrumenter.CAPTURE_ID_JAVA_UTIL_CALENDAR, this, ret);
  return ret;
}

相关文章