Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
573 views
in Technique[技术] by (71.8m points)

simpledateformat - java date format - GMT 0700 (PDT)

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?

SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss 'GMT-0700' (z)");
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

To be more precise, in SimpleDateFormat formats :

  • 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.

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.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...