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

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

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

SimpleDateFormat.setCalendar介绍

暂无

代码示例

代码示例来源:origin: apache/maven

public MavenBuildTimestamp( Date time, String timestampFormat )
{
  if ( timestampFormat == null )
  {
    timestampFormat = DEFAULT_BUILD_TIMESTAMP_FORMAT;
  }
  if ( time == null )
  {
    time = new Date();
  }
  SimpleDateFormat dateFormat = new SimpleDateFormat( timestampFormat );
  dateFormat.setCalendar( new GregorianCalendar() );
  dateFormat.setTimeZone( DEFAULT_BUILD_TIME_ZONE );
  formattedTimestamp = dateFormat.format( time );
}

代码示例来源:origin: org.mongodb/mongo-java-driver

@Override
public void serialize(final Object obj, final StringBuilder buf) {
  Date d = (Date) obj;
  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
  format.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT")));
  serializer.serialize(new BasicDBObject("$date", format.format(d)), buf);
}

代码示例来源:origin: elastic/elasticsearch-hadoop

@Override
  public String format(String value) {
    if (!StringUtils.hasText(value)) {
      return null;
    }

    Calendar calendar = DateUtils.parseDate(value);
    dateFormat.setCalendar(calendar);
    return dateFormat.format(calendar.getTime());
  }
}

代码示例来源:origin: org.mongodb/mongo-java-driver

} else {
  SimpleDateFormat format = new SimpleDateFormat(_msDateFormat);
  format.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT")));
  o = format.parse(b.get("$date").toString(), new ParsePosition(0));
    format.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT")));
    o = format.parse(b.get("$date").toString(), new ParsePosition(0));

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

@Override
public String convertToString(Object object) {
  if (object instanceof GregorianCalendar == false) {
    throw new RuntimeException("Unable to convert calendar as it is not a GregorianCalendar");
  }
  GregorianCalendar cal = (GregorianCalendar) object;
  SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
  f.setCalendar(cal);
  String str = f.format(cal.getTime());
  return str.substring(0, 26) + ":" + str.substring(26) + "[" + cal.getTimeZone().getID() + "]";
}
@Override

代码示例来源: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: apache/pdfbox

private static GregorianCalendar parseSimpleDate(String text, String[] fmts,
    ParsePosition initialWhere) 
{
  for(String fmt : fmts)
  {
    ParsePosition where = new ParsePosition(initialWhere.getIndex());
    SimpleDateFormat sdf = new SimpleDateFormat(fmt, Locale.ENGLISH);
    GregorianCalendar retCal = newGreg();
    sdf.setCalendar(retCal);
    if (sdf.parse(text, where) != null)
    {
      initialWhere.setIndex(where.getIndex());
      skipOptionals(text, initialWhere, " ");
      return retCal;
    }
  }
  return null;
}

代码示例来源:origin: i2p/i2p.i2p

public RouterKeyGenerator(I2PAppContext context) {
  _log = context.logManager().getLog(RoutingKeyGenerator.class);
  _context = context;
  // make sure GMT is set, azi2phelper Vuze plugin is disabling static JVM TZ setting in Router.java
  _fmt.setCalendar(_cal);
  // ensure non-null mod data
  generateDateBasedModData();
}

代码示例来源:origin: openstreetmap/osmosis

private DateFormat getRequestDateParser() {
  SimpleDateFormat dateParser = new SimpleDateFormat(REQUEST_DATE_FORMAT);
  Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
  dateParser.setCalendar(calendar);
  return dateParser;
}

代码示例来源:origin: org.mule/mule-core

public DateTime(String dateString, String format) throws ParseException
{
  this(Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.getDefault()), Locale.getDefault());
  SimpleDateFormat dateFormat = new SimpleDateFormat(format);
  dateFormat.setCalendar(this.calendar);
  dateFormat.parse(dateString);
}

代码示例来源:origin: org.mule.runtime/mule-core

public DateTime(String dateString, String format) throws ParseException {
 this(Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.getDefault()), Locale.getDefault());
 SimpleDateFormat dateFormat = new SimpleDateFormat(format);
 dateFormat.setCalendar(this.calendar);
 dateFormat.parse(dateString);
}

代码示例来源:origin: org.mongodb/mongodb-driver

@Override
public void serialize(final Object obj, final StringBuilder buf) {
  Date d = (Date) obj;
  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
  format.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT")));
  serializer.serialize(new BasicDBObject("$date", format.format(d)), buf);
}

代码示例来源:origin: org.drizzle.jdbc/drizzle-jdbc

public Timestamp getTimestamp(final Calendar cal) throws ParseException {
  if (rawBytes == null) {
    return null;
  }
  final String rawValue = getString();
  final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  sdf.setCalendar(cal);
  final java.util.Date utilTime = sdf.parse(rawValue);
  return new Timestamp(utilTime.getTime());
}

代码示例来源:origin: com.github.os72/protobuf-java-util-shaded-351

private static SimpleDateFormat createTimestampFormat() {
 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH);
 GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
 // We use Proleptic Gregorian Calendar (i.e., Gregorian calendar extends
 // backwards to year one) for timestamp formating.
 calendar.setGregorianChange(new Date(Long.MIN_VALUE));
 sdf.setCalendar(calendar);
 return sdf;
}

代码示例来源:origin: fr.opensagres.mongodb/mongo-jee

@Override
protected void serialize(Object obj, Writer writer, OutputStream out)
    throws IOException {        
  Date d = (Date) obj;
  SimpleDateFormat format = new SimpleDateFormat(
      "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
  format.setCalendar(new GregorianCalendar(
      new SimpleTimeZone(0, "GMT")));
  JSON.serialize(serializer,
      new BasicDBObject("$date", format.format(d)), writer, out);
}

代码示例来源:origin: com.google.protobuf/protobuf-java-util

private static SimpleDateFormat createTimestampFormat() {
 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH);
 GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
 // We use Proleptic Gregorian Calendar (i.e., Gregorian calendar extends
 // backwards to year one) for timestamp formating.
 calendar.setGregorianChange(new Date(Long.MIN_VALUE));
 sdf.setCalendar(calendar);
 return sdf;
}

代码示例来源:origin: org.apache.ratis/ratis-proto-shaded

private static SimpleDateFormat createTimestampFormat() {
 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH);
 GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
 // We use Proleptic Gregorian Calendar (i.e., Gregorian calendar extends
 // backwards to year one) for timestamp formating.
 calendar.setGregorianChange(new Date(Long.MIN_VALUE));
 sdf.setCalendar(calendar);
 return sdf;
}

代码示例来源:origin: org.elasticsearch/elasticsearch-hadoop-mr

@Override
  public String format(String value) {
    if (!StringUtils.hasText(value)) {
      return null;
    }

    Calendar calendar = DateUtils.parseDate(value);
    dateFormat.setCalendar(calendar);
    return dateFormat.format(calendar.getTime());
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch-spark-13

@Override
  public String format(String value) {
    if (!StringUtils.hasText(value)) {
      return null;
    }

    Calendar calendar = DateUtils.parseDate(value);
    dateFormat.setCalendar(calendar);
    return dateFormat.format(calendar.getTime());
  }
}

代码示例来源:origin: googlesamples/android-WatchFace

private void initFormats() {
  mDayOfWeekFormat = new SimpleDateFormat("EEEE", Locale.getDefault());
  mDayOfWeekFormat.setCalendar(mCalendar);
  mDateFormat = DateFormat.getDateFormat(DigitalWatchFaceService.this);
  mDateFormat.setCalendar(mCalendar);
}

相关文章

SimpleDateFormat类方法