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

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

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

SimpleDateFormat.setTimeZone介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-framework

private DateFormat newDateFormat() {
  SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.US);
  dateFormat.setTimeZone(GMT);
  return dateFormat;
}

代码示例来源:origin: spring-projects/spring-framework

private long parseDateHeader(String name, String value) {
  for (String dateFormat : DATE_FORMATS) {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat, Locale.US);
    simpleDateFormat.setTimeZone(GMT);
    try {
      return simpleDateFormat.parse(value).getTime();
    }
    catch (ParseException ex) {
      // ignore
    }
  }
  throw new IllegalArgumentException("Cannot parse date value '" + value + "' for '" + name + "' header");
}

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

public String getCurTime() {
  String fromTimeZone = "GMT+8";
  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  Date date = new Date();
  format.setTimeZone(TimeZone.getTimeZone(fromTimeZone));
  String chinaDate = format.format(date);
  return chinaDate;
}

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

public static String dateToString(Date date) {
    if (date != null) {
      SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_PATTERN);
      simpleDateFormat.setTimeZone(UTC);
      return simpleDateFormat.format(date);
    }

    return "";
  }
}

代码示例来源:origin: elvishew/xLog

/**
  * Generate a file name which represent a specific date.
  */
 @Override
 public String generateFileName(int logLevel, long timestamp) {
  SimpleDateFormat sdf = mLocalDateFormat.get();
  sdf.setTimeZone(TimeZone.getDefault());
  return sdf.format(new Date(timestamp));
 }
}

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

private SimpleDateFormat createSimpleDateFormat() {
    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    fmt.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
    return fmt;
  }
}

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

public final String formatUTCTZ(Date date) {
  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
  sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
  return sdf.format(date);
}

代码示例来源:origin: spring-projects/spring-framework

private long parseDateValue(@Nullable String headerValue) {
  if (headerValue == null) {
    // No header value sent at all
    return -1;
  }
  if (headerValue.length() >= 3) {
    // Short "0" or "-1" like values are never valid HTTP date headers...
    // Let's only bother with SimpleDateFormat parsing for long enough values.
    for (String dateFormat : DATE_FORMATS) {
      SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat, Locale.US);
      simpleDateFormat.setTimeZone(GMT);
      try {
        return simpleDateFormat.parse(headerValue).getTime();
      }
      catch (ParseException ex) {
        // ignore
      }
    }
  }
  return -1;
}

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

public static String dateToString(Date date) {
    if (date != null) {
      SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_PATTERN);
      simpleDateFormat.setTimeZone(UTC);
      return simpleDateFormat.format(date);
    }

    return "";
  }
}

代码示例来源:origin: jwtk/jjwt

@Override
  protected DateFormat initialValue() {
    SimpleDateFormat format = new SimpleDateFormat(ISO_8601_PATTERN);
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    return format;
  }
};

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

private RFC1123()
{
  format = new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss Z", Locale.US );
  format.setTimeZone( GMT );
}

代码示例来源:origin: org.testng/testng

/**
   * @param timeInMilliSeconds - The time in milliseconds
   * @param format             - A format that can be used by {@link SimpleDateFormat}
   * @return - A formatted string representation of the time in UTC/GMT timezone.
   */
  public static String timeInUTC(long timeInMilliSeconds, String format) {
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    TimeZone utc = TimeZone.getTimeZone("UTC");
    sdf.setTimeZone(utc);
    return sdf.format(timeInMilliSeconds);
  }
}

代码示例来源:origin: jeasonlzy/okhttp-OkGo

public static long parseGMTToMillis(String gmtTime) throws ParseException {
  if (TextUtils.isEmpty(gmtTime)) return 0;
  SimpleDateFormat formatter = new SimpleDateFormat(FORMAT_HTTP_DATA, Locale.US);
  formatter.setTimeZone(GMT_TIME_ZONE);
  Date date = formatter.parse(gmtTime);
  return date.getTime();
}

代码示例来源:origin: com.h2database/h2

String getStartDateTime() {
  if (startDateTime == null) {
    SimpleDateFormat format = new SimpleDateFormat(
        "EEE, d MMM yyyy HH:mm:ss z", new Locale("en", ""));
    format.setTimeZone(DateTimeUtils.UTC);
    startDateTime = format.format(System.currentTimeMillis());
  }
  return startDateTime;
}

代码示例来源:origin: jwtk/jjwt

@Override
  protected DateFormat initialValue() {
    SimpleDateFormat format = new SimpleDateFormat(ISO_8601_MILLIS_PATTERN);
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    return format;
  }
};

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

public StoreFiles( DatabaseLayout databaseLayout )
{
  this.databaseLayout = databaseLayout;
  TimeZone tz = TimeZone.getDefault();
  dateFormat = new SimpleDateFormat( FORMAT_DATE_ISO );
  dateFormat.setTimeZone( tz );
}

代码示例来源:origin: jeasonlzy/okhttp-OkGo

public static String formatMillisToGMT(long milliseconds) {
  Date date = new Date(milliseconds);
  SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FORMAT_HTTP_DATA, Locale.US);
  simpleDateFormat.setTimeZone(GMT_TIME_ZONE);
  return simpleDateFormat.format(date);
}

代码示例来源:origin: yanzhenjie/NoHttp

/**
 * Parsing the TimeZone of time in milliseconds.
 *
 * @param gmtTime GRM Time, Format such as: {@value #FORMAT_HTTP_DATA}.
 * @return The number of milliseconds from 1970.1.1.
 * @throws ParseException if an error occurs during parsing.
 */
public static long parseGMTToMillis(String gmtTime) throws ParseException {
  SimpleDateFormat formatter = new SimpleDateFormat(FORMAT_HTTP_DATA, Locale.US);
  formatter.setTimeZone(GMT_TIME_ZONE);
  Date date = formatter.parse(gmtTime);
  return date.getTime();
}

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

public static String dateToString(Date date) {
    if (date != null) {
      SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_PATTERN_FOR_V3);
      simpleDateFormat.setTimeZone(UTC);
      return simpleDateFormat.format(date);
    }

    return "";
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Before
public void setup() throws URISyntaxException {
  this.currentDate = Instant.now().truncatedTo(ChronoUnit.SECONDS);
  this.dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
  this.dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
}

相关文章

SimpleDateFormat类方法