-1

Possible Duplicate:
how to parse date in java?
How do I convert 2010-12-15T16:26:49.841-08:00 to a GregorianCalendar in Java?

Example string:

2009-06-04T11:17:14-07:00

I am not sure how to construct the formatter string for this one. Anyone can help please? Thanks! :)

7
  • what have you tried? what is the format of your example date string? what does the T mean?! Commented Oct 8, 2012 at 5:50
  • What the "-07:00" means in the date? Commented Oct 8, 2012 at 5:51
  • @LuiggiMendoza: It's an offset specifier from UTC. Commented Oct 8, 2012 at 6:09
  • @JonSkeet reading the link of Java 7 in your answer gave me the light. Thanks. Commented Oct 8, 2012 at 6:10
  • See this answer. Commented Oct 8, 2012 at 9:23

1 Answer 1

4

This looks like a perfectly normal ISO-8601 date/time to me. You should be able to parse it with either SimpleDateFormat using the built-in APIs, or DateTimeFormatter in Joda Time, using the pattern "yyyy-MM-dd'T'HH:mm:ssX" (SimpleDateFormat) or "yyyy-MM-dd'T'HH:mm:ssZ" (DateTimeFormatter). Note that the "X" format symbol was only introduced into Java 7; if you need to do this in Java 6 or earlier you may need to strip the colon within the offset text (so -07:00 would become -0700).

Personally I'd advise you to use Joda Time anyway - it gets round the Java version issue, and it's much nicer API in general.

Sign up to request clarification or add additional context in comments.

9 Comments

SimpleDateFormat unfortunately can't deal with the : in the timezone.
@Jesper: That answer was from December 2010, before Java 7 was released with the "Z" format specifier.
Ah, I didn't know that this was changed in Java 7! Thanks.
I didn't know the change made in Java7 either. Thanks a lot for your advice! Currently i still use default Java 6. Can u help vote for my question? I think I asked a good question and learned a lot from your answer. Feel pretty upset on someone down vote my question...>.<
@nanshi: Well, you didn't show what you'd tried - how far you'd got, etc...
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.