java.text.DateFormat.setTimeZone()方法的使用及代码示例

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

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

DateFormat.setTimeZone介绍

[英]Sets the time zone of the calendar used by this date format.
[中]设置此日期格式使用的日历的时区。

代码示例

代码示例来源:origin: square/okhttp

@Override protected DateFormat initialValue() {
  // Date format specified by RFC 7231 section 7.1.1.1.
  DateFormat rfc1123 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
  rfc1123.setLenient(false);
  rfc1123.setTimeZone(UTC);
  return rfc1123;
 }
};

代码示例来源:origin: jenkinsci/jenkins

private static String clientDateString() {
  TimeZone tz = TimeZone.getTimeZone("UTC");
  DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
  df.setTimeZone(tz); // strip timezone
  return df.format(new Date());
}

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

/**
   * @{inheritDoc}
   */
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
  dateFormat.setTimeZone(TimeZone.getDefault());
  return dateFormat.format(date, toAppendTo, fieldPosition);
}

代码示例来源:origin: square/okhttp

Date result = STANDARD_DATE_FORMAT.get().parse(value, position);
if (position.getIndex() == value.length()) {
  DateFormat format = BROWSER_COMPATIBLE_DATE_FORMATS[i];
  if (format == null) {
   format = new SimpleDateFormat(BROWSER_COMPATIBLE_DATE_FORMAT_STRINGS[i], Locale.US);
   format.setTimeZone(UTC);
   BROWSER_COMPATIBLE_DATE_FORMATS[i] = format;
  result = format.parse(value, position);
  if (position.getIndex() != 0) {

代码示例来源:origin: stackoverflow.com

SimpleDateFormat format = new SimpleDateFormat(
  "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
format.setTimeZone(TimeZone.getTimeZone("UTC"));

代码示例来源:origin: alibaba/fastjson

public void write(JSONSerializer serializer, Object object, BeanContext context) throws IOException {
  SerializeWriter out = serializer.out;
  String format = context.getFormat();
  Calendar calendar = (Calendar) object;
  if (format.equals("unixtime")) {
    long seconds = calendar.getTimeInMillis() / 1000L;
    out.writeInt((int) seconds);
    return;
  }
  DateFormat dateFormat = new SimpleDateFormat(format);
  if (dateFormat == null) {
    dateFormat = new SimpleDateFormat(JSON.DEFFAULT_DATE_FORMAT, serializer.locale);
    dateFormat.setTimeZone(serializer.timeZone);
  }
  String text = dateFormat.format(calendar.getTime());
  out.writeString(text);
}

代码示例来源:origin: stackoverflow.com

localSimpleDateFormat = new ThreadLocal<SimpleDateFormat>() {
  protected SimpleDateFormat initialValue() {
    return new SimpleDateFormat();
localSimpleDateFormat = new ThreadLocal<SimpleDateFormat>() {
  protected SimpleDateFormat initialValue() {
    return new SimpleDateFormat(pattern);
localSimpleDateFormat = new ThreadLocal<SimpleDateFormat>() {
  protected SimpleDateFormat initialValue() {
    return new SimpleDateFormat(pattern, formatSymbols);
return localSimpleDateFormat.get().parse(source);
localSimpleDateFormat.get().setTimeZone(zone);

代码示例来源:origin: knowm/XChange

public static Date parseDate(String dateString) {

  // 2015-04-13T07:56:36.185Z

  format.setTimeZone(TimeZone.getTimeZone("GMT"));

  try {
   return format.parse(dateString);
  } catch (ParseException e) {
   return null;
  }
 }
}

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

public
void activateOptions() {
 setDateFormat(dateFormatOption);
 if(timeZoneID != null && dateFormat != null) {
  dateFormat.setTimeZone(TimeZone.getTimeZone(timeZoneID));
 }
}

代码示例来源:origin: stackoverflow.com

SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT"));

//Local time zone   
SimpleDateFormat dateFormatLocal = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");

//Time in GMT
return dateFormatLocal.parse( dateFormatGmt.format(new Date()) );

代码示例来源:origin: prestodb/presto

Date result = STANDARD_DATE_FORMAT.get().parse(value, position);
if (position.getIndex() == value.length()) {
  DateFormat format = BROWSER_COMPATIBLE_DATE_FORMATS[i];
  if (format == null) {
   format = new SimpleDateFormat(BROWSER_COMPATIBLE_DATE_FORMAT_STRINGS[i], Locale.US);
   format.setTimeZone(UTC);
   BROWSER_COMPATIBLE_DATE_FORMATS[i] = format;
  result = format.parse(value, position);
  if (position.getIndex() != 0) {

代码示例来源:origin: prestodb/presto

@Override protected DateFormat initialValue() {
  // Date format specified by RFC 7231 section 7.1.1.1.
  DateFormat rfc1123 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
  rfc1123.setLenient(false);
  rfc1123.setTimeZone(UTC);
  return rfc1123;
 }
};

代码示例来源:origin: knowm/XChange

private static DateFormat getDateFormat() {
 DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_STRING);
 dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
 return dateFormat;
}

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

String format( Date date, TimeZone timeZone )
{
  DateFormat dateFormat = get();
  dateFormat.setTimeZone( timeZone );
  return dateFormat.format( date );
}

代码示例来源:origin: eugenp/tutorials

protected void init() {
  // Use RFC3339 format for date and datetime.
  // See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14
  this.dateFormat = new RFC3339DateFormat();
  // Use UTC as the default time zone.
  this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
  // Set default User-Agent.
  setUserAgent("Java-SDK");
  // Setup authentications (key: authentication name, value: authentication).
  authentications = new HashMap<String, Authentication>();
  authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
  authentications.put("petstore_auth", new OAuth());
  // Prevent the authentications from being modified.
  authentications = Collections.unmodifiableMap(authentications);
}

代码示例来源:origin: stackoverflow.com

TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
df.setTimeZone(tz);
String nowAsISO = df.format(new Date());

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Sets the executionTime which is in standard format ({@link #SIGNATURE_TIME_FORMAT})
 * @param executionTime the execution time
 *
 * @since POI 4.0.0
 */
public void setExecutionTime(String executionTime) {
  if (executionTime != null && !"".equals(executionTime)){
    final DateFormat fmt = new SimpleDateFormat(SIGNATURE_TIME_FORMAT, Locale.ROOT);
    fmt.setTimeZone(LocaleUtil.TIMEZONE_UTC);
    try {
      this.executionTime = fmt.parse(executionTime);
    } catch (ParseException e) {
      LOG.log(POILogger.WARN, "Illegal execution time: "+executionTime);
    }
  }
}

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

public static DateFormat getOutDateFormatter() {
  DateFormat f = new SimpleDateFormat(SvnCommand.SVN_DATE_FORMAT_OUT);
  f.setTimeZone(UTC);
  return f;
}

代码示例来源:origin: stackoverflow.com

SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
isoFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = isoFormat.parse("2010-05-23T09:01:02");

代码示例来源:origin: com.squareup.okhttp3/okhttp

Date result = STANDARD_DATE_FORMAT.get().parse(value, position);
if (position.getIndex() == value.length()) {
  DateFormat format = BROWSER_COMPATIBLE_DATE_FORMATS[i];
  if (format == null) {
   format = new SimpleDateFormat(BROWSER_COMPATIBLE_DATE_FORMAT_STRINGS[i], Locale.US);
   format.setTimeZone(UTC);
   BROWSER_COMPATIBLE_DATE_FORMATS[i] = format;
  result = format.parse(value, position);
  if (position.getIndex() != 0) {

相关文章