java 日期格式 - GMT 0700 (PDT)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18493528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 08:31:37  来源:igfitidea点击:

java date format - GMT 0700 (PDT)

javasimpledateformat

提问by Cacheing

This is the date format that I need to deal with

这是我需要处理的日期格式

Wed Aug 21 2013 00:00:00 GMT-0700 (PDT)

But I don't get what the last two parts are. Is the GMT-0700fixed? Should it be something like this?

但我不明白最后两部分是什么。是GMT-0700固定的吗?应该是这样的吗?

SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss 'GMT-0700' (z)");

采纳答案by Arnaud Denoyelle

No, it is not fixed. It is a TimeZone. You can match it with Zin the date format.

不,它不是固定的。这是一个时区。您可以将其与Z日期格式匹配。

To be more precise, in SimpleDateFormatformats :

更准确地说,在SimpleDateFormat格式中:

  • Zmatches the -0700part.
  • GMTis fixed. Escape it with some quotes.
  • z matches the PDTpart. (PDT = Pacific Daylight Time).
  • The parenthesis around PDT are fixed. Escape them with parenthesis.
  • Z匹配-0700部分。
  • GMT是固定的。用一些引号将其转义。
  • z 匹配PDT零件。(PDT = 太平洋夏令时)。
  • PDT 周围的括号是固定的。用括号将它们转义。

You can parse your date with the following format :

您可以使用以下格式解析您的日期:

EEE MMM dd yyyy HH:mm:ss 'GMT'Z '('z')'

Another remark: Wed Augcontains the day and month in English so you must use an english locale with your SimpleDateFormat or the translation will fail.

另一个备注Wed Aug包含英文的日和月,因此您必须在 SimpleDateFormat 中使用英文区域设置,否则翻译将失败

new SimpleDateFormat("*format*", Locale.ENGLISH);

回答by paulsm4

Here is the Javadoc:

这是Javadoc:

http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

For this example: Wed Aug 21 2013 00:00:00 GMT-0700 (PDT), you'd want this format:

对于此示例:Wed Aug 21 2013 00:00:00 GMT-0700 (PDT),您需要以下格式:

import java.text.SimpleDateFormat;
import java.util.Date;

public class JavaDate {

  public static void main (String[] args) throws Exception {

    String s= "Wed Aug 21 2013 00:00:00 GMT-0700 (PDT)";
    SimpleDateFormat sdf = 
      new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss 'GMT'z '('Z')'");
    Date d = sdf.parse (s);
    System.out.println ("Date=" + d + "...");
  }
}

EXAMPLE OUTPUT: Date=Tue Aug 20 23:00:00 PDT 2013...

示例输出:日期= 2013 年 8 月 20 日星期二 23:00:00 PDT...

Thanx to Arnaud Denoyelle above for his edits!

感谢上面的 Arnaud Denoyelle 的编辑!