java.text.SimpleDateFormat.getCalendar()方法的使用及代码示例

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

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

SimpleDateFormat.getCalendar介绍

暂无

代码示例

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

JacksonThymeleafISO8601DateFormat() {
  super();
  this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZZ");
  setCalendar(this.dateFormat.getCalendar());
  setNumberFormat(this.dateFormat.getNumberFormat());
}

代码示例来源:origin: org.joda/joda-convert

@Override
  public Object convertFromString(Class<?> cls, String str) {
    if (str.length() < 31 || str.charAt(26) != ':'
        || str.charAt(29) != '[' || str.charAt(str.length() - 1) != ']') {
      throw new IllegalArgumentException("Unable to parse date: " + str);
    }
    TimeZone zone = TimeZone.getTimeZone(str.substring(30, str.length() - 1));
    String str2 = str.substring(0, 26) + str.substring(27, 29);
    SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
    GregorianCalendar cal = new GregorianCalendar(zone);
    cal.setTimeInMillis(0);
    f.setCalendar(cal);
    try {
      f.parseObject(str2);
      return f.getCalendar();
    } catch (ParseException ex) {
      throw new RuntimeException(ex);
    }
  }
},

代码示例来源:origin: org.leapframework/leap-lang

@Override
public synchronized Calendar getCalendar() {
  return format.getCalendar();
}

代码示例来源:origin: org.refcodes/refcodes-date

/**
 * {@inheritDoc}
 * 
 * @deprecated as it is not considered to be thread safe.
 */
@Deprecated
@Override
public Calendar getCalendar() {
  return super.getCalendar();
}

代码示例来源:origin: com.novoda/notils

public Calendar getCalendar() {
  return localSimpleDateFormat.get().getCalendar();
}

代码示例来源:origin: novoda/notils

public Calendar getCalendar() {
  return localSimpleDateFormat.get().getCalendar();
}

代码示例来源:origin: com.healthmarketscience.jackcess/jackcess

/**
 * Returns a SimpleDateFormat for the given format string which is
 * configured with a compatible Calendar instance (see
 * {@link #toCompatibleCalendar}).
 */
public static SimpleDateFormat createDateFormat(String formatStr) {
 SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
 toCompatibleCalendar(sdf.getCalendar());
 return sdf;
}

代码示例来源:origin: net.sf.ucanaccess/ucanaccess

static SimpleDateFormat createSimpleDateFormat(String pt) {
  SimpleDateFormat sdf = new SimpleDateFormat(pt);
  ((GregorianCalendar) sdf.getCalendar()).setGregorianChange(new java.util.Date(Long.MIN_VALUE));
  return sdf;
}

代码示例来源:origin: org.bitbucket.ibencher/ToxGene

/**
 * Constructor for dates from Strings
 */
public Date(String value) throws DateFormatException{
 df = new SimpleDateFormat("yyyy-MM-dd");
 try{
  df.parse(value);
  calendar = (GregorianCalendar) df.getCalendar();
 }catch (ParseException e){
  throw new DateFormatException();
 }
}

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

public Object decode(String data) throws DataDecodeException {
    if (decoder == null) {
      throw new IllegalStateException("Calendar decoder not initialised.  A decoder for this type (" + getClass().getName() + ") must be explicitly configured (unlike the primitive type decoders) with a date 'format'. See Javadoc.");
    }
    try {
      // Must be sync'd - DateFormat is not synchronized.
      synchronized(decoder) {
        decoder.parse(data.trim());
        return decoder.getCalendar().clone();
      }
    } catch (ParseException e) {
      throw new DataDecodeException("Error decoding Date data value '" + data + "' with decode format '" + format + "'.", e);
    }
  }
}

代码示例来源:origin: org.milyn/milyn-commons

public Object decode(String data) throws DataDecodeException {
    if (decoder == null) {
      throw new IllegalStateException("Calendar decoder not initialised.  A decoder for this type (" + getClass().getName() + ") must be explicitly configured (unlike the primitive type decoders) with a date 'format'. See Javadoc.");
    }
    try {
      // Must be sync'd - DateFormat is not synchronized.
      synchronized(decoder) {
        decoder.parse(data.trim());
        return decoder.getCalendar().clone();
      }
    } catch (ParseException e) {
      throw new DataDecodeException("Error decoding Date data value '" + data + "' with decode format '" + format + "'.", e);
    }
  }
}

代码示例来源:origin: org.milyn/milyn-smooks-all

public Object decode(String data) throws DataDecodeException {
    if (decoder == null) {
      throw new IllegalStateException("Calendar decoder not initialised.  A decoder for this type (" + getClass().getName() + ") must be explicitly configured (unlike the primitive type decoders) with a date 'format'. See Javadoc.");
    }
    try {
      // Must be sync'd - DateFormat is not synchronized.
      synchronized(decoder) {
        decoder.parse(data.trim());
        return decoder.getCalendar().clone();
      }
    } catch (ParseException e) {
      throw new DataDecodeException("Error decoding Date data value '" + data + "' with decode format '" + format + "'.", e);
    }
  }
}

代码示例来源:origin: redfish64/TinyTravelTracker

public Object convertFromString(Class<?> cls, String str) {
    if (str.length() < 31 || str.charAt(26) != ':'
        || str.charAt(29) != '[' || str.charAt(str.length() - 1) != ']') {
      throw new IllegalArgumentException("Unable to parse date: " + str);
    }
    TimeZone zone = TimeZone.getTimeZone(str.substring(30, str.length() - 1));
    str = str.substring(0, 26) + str.substring(27, 29);
    SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
    GregorianCalendar cal = new GregorianCalendar(zone);
    cal.setTimeInMillis(0);
    f.setCalendar(cal);
    try {
      f.parseObject(str);
      return f.getCalendar();
    } catch (ParseException ex) {
      throw new RuntimeException(ex);
    }
  }
},

代码示例来源:origin: net.time4j/time4j-core

private static void updateRawValues(
  RawValues rawValues,
  SimpleDateFormat sdf
) {
  if (rawValues != null) {
    rawValues.accept(new Parsed(XCalendar.class.cast(sdf.getCalendar())));
  }
}

代码示例来源:origin: com.baidu.hugegraph/hugegraph-common

public SafeDateFormat(String template) {
  this.formatter = ThreadLocal.withInitial(() -> {
    return new SimpleDateFormat(template);
  });
  this.setCalendar(this.formatter.get().getCalendar());
  this.setNumberFormat(this.formatter.get().getNumberFormat());
}

代码示例来源:origin: usethesource/rascal

public IValue parseDateTime(IString inputDateTime, IString formatString) 
//@doc{Parse an input datetime given as a string using the given format string}
{
  try {
    java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat(formatString.getValue());
    fmt.setLenient(false);
    fmt.parse(inputDateTime.getValue());
    java.util.Calendar cal = fmt.getCalendar();
    int zoneHours = cal.get(Calendar.ZONE_OFFSET) / (1000 * 60 * 60);
    int zoneMinutes = (cal.get(Calendar.ZONE_OFFSET) / (1000 * 60)) % 60; 
    return values.datetime(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), zoneHours, zoneMinutes);
  } catch (IllegalArgumentException iae) {
    throw RuntimeExceptionFactory.dateTimeParsingError("Cannot parse input datetime: " + inputDateTime.getValue() + 
        " using format string: " + formatString.getValue(), null, null);
  } catch (ParseException e) {
    throw RuntimeExceptionFactory.dateTimeParsingError("Cannot parse input datetime: " + inputDateTime.getValue() + 
        " using format string: " + formatString.getValue(), null, null);
  }            
}

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

@Override
public java.util.Calendar getCalendar() {
  Capturer.capture(Instrumenter.CAPTURE_ID_JAVA_TEXT_SIMPLEDATEFORMAT, this, "getCalendar", "()Ljava/util/Calendar;", new Object[] {});
  java.util.Calendar ret = new Calendar(super.getCalendar());
  Capturer.enable(Instrumenter.CAPTURE_ID_JAVA_TEXT_SIMPLEDATEFORMAT, this, ret);
  return ret;
}

代码示例来源:origin: usethesource/rascal

public IValue parseDateTimeInLocale(IString inputDateTime, IString formatString, IString locale) 
//@doc{Parse an input datetime given as a string using a specific locale and format string}
{
  try {
    java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat(formatString.getValue(), new Locale(locale.getValue()));
    fmt.parse(inputDateTime.getValue());
    java.util.Calendar cal = fmt.getCalendar();
    int zoneHours = cal.get(Calendar.ZONE_OFFSET) / (1000 * 60 * 60);
    int zoneMinutes = (cal.get(Calendar.ZONE_OFFSET) / (1000 * 60)) % 60; 
    return values.datetime(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), zoneHours, zoneMinutes);
  } catch (IllegalArgumentException iae) {
    throw RuntimeExceptionFactory.dateTimeParsingError("Cannot parse input datetime: " + inputDateTime.getValue() + 
        " using format string: " + formatString.getValue() + " in locale: " + locale.getValue(), null, null);
  } catch (ParseException e) {
    throw RuntimeExceptionFactory.dateTimeParsingError("Cannot parse input datetime: " + inputDateTime.getValue() + 
        " using format string: " + formatString.getValue() + " in locale: " + locale.getValue(), null, null);
  }
}

代码示例来源:origin: usethesource/rascal

public IValue parseDate(IString inputDate, IString formatString)
//@doc{Parse an input date given as a string using the given format string}
{    
  try {
    java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat(formatString.getValue());
    fmt.parse(inputDate.getValue());
    java.util.Calendar cal = fmt.getCalendar();
    return values.date(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DATE));
  } catch (IllegalArgumentException iae) {
    throw RuntimeExceptionFactory.dateTimeParsingError("Cannot parse input date: " + inputDate.getValue() + 
        " using format string: " + formatString.getValue(), null, null);
  } catch (ParseException e) {
    throw RuntimeExceptionFactory.dateTimeParsingError("Cannot parse input date: " + inputDate.getValue() + 
        " using format string: " + formatString.getValue(), null, null);
  }
}

代码示例来源:origin: usethesource/rascal

public IValue parseDateInLocale(IString inputDate, IString formatString, IString locale) 
//@doc{Parse an input date given as a string using a specific locale and format string}
{
  try {
    java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat(formatString.getValue(), new Locale(locale.getValue()));
    fmt.parse(inputDate.getValue());
    java.util.Calendar cal = fmt.getCalendar();
    return values.date(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DATE));
  } catch (IllegalArgumentException iae) {
    throw RuntimeExceptionFactory.dateTimeParsingError("Cannot parse input date: " + inputDate.getValue() + 
        " using format string: " + formatString.getValue() + " in locale: " + locale.getValue(), null, null);
  } catch (ParseException e) {
    throw RuntimeExceptionFactory.dateTimeParsingError("Cannot parse input date: " + inputDate.getValue() + 
        " using format string: " + formatString.getValue() + " in locale: " + locale.getValue(), null, null);
  }
}

相关文章

SimpleDateFormat类方法