0

I am porting some of our app from c# to java. Some data objects get xml serialized and stored for later use. The built in .net xml serialization automatically saves DateTime properties in the format below:

2009-05-11T16:47:08.6033346-04:00

How can I get this into a Date object in Java? I read that the date format is ISO 8601 which labled as SortableDateTime in the MSDN documentation.

Thanks!

1
  • FYI, this format is specified for use in XML documents by the W3C Schema spec. w3.org/TR/xmlschema-2/#dateTime It's not just something .NET happens to do Commented Jun 16, 2009 at 23:12

2 Answers 2

1

Use the following snippet:

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


SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date d = sdf.parse("2009-05-11T16:47:08.6033346-04:00");
Sign up to request clarification or add additional context in comments.

Comments

1

parseDateTime?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.