tags:

views:

190

answers:

2

I am parsing xml file. In this file there is one tag containing date string

 "2008-11-10T05:51:33Z" 

And I want convert this string in to java.util.Date object.

is there any body who will help me...

+8  A: 

Use java.text.DateFormat - or more likely, SimpleDateFormat.

Alternatively, go for Joda Time with its infinitely better API. Be careful with the Java built-in APIs - DateFormats aren't thread-safe. (They are in Joda Time, which uses immutable types almost everywhere.)

An (untested - should be fine except for possibly the timezone bit) example for the Joda Time API:

DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd'T'HH:mm:ssZ");
DateTime dt = fmt.parse("2008-11-10T05:51:33Z");
Jon Skeet
One thing to note about Joda time, if you're writing mobile or embedded apps it is HUGE (like 500k).
fiXedd
A: 
DateTime dateToGetFromString;

dateToGetFromString = DateTime.Parse(stringContainingDate);

You can also use the TryParse function of DateTime class, look in the documentation.

Raminder
Sorry thought it was .Net
Raminder