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
java date format - GMT 0700 (PDT)
提问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-0700
fixed? 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 Z
in the date format.
不,它不是固定的。这是一个时区。您可以将其与Z
日期格式匹配。
To be more precise, in SimpleDateFormatformats :
更准确地说,在SimpleDateFormat格式中:
Z
matches the-0700
part.GMT
is fixed. Escape it with some quotes.- z matches the
PDT
part. (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 Aug
contains 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 的编辑!