tags:

views:

70

answers:

3

I have a string that contains the date/time returned from a web service like so:

String dtStart = "2010-10-15T09:27:37Z"

How do I get this into an object such as Time or Date? I initially want to output it in a different format, but will need to do other stuff with it later (i.e. maybe use in a different format).

Cheers

A: 

DateFormat.parse(dtStart)

Rich
A: 

You can use Java's SimpleDateFormat parse method or use JodaTime's DateTimeFormat to create a DateTimeFormatter and parse to a DateTime object accordingly

Jeroen Rosenberg
+1  A: 
String dtStart = "2010-10-15T09:27:37Z";  
SimpleDateFormat  format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");  
try {  
    Date date = format.parse(dtStart);  
    System.out.println(date);  
} catch (ParseException e) {  
    // TODO Auto-generated catch block  
    e.printStackTrace();  
}

This is what you are looking for. There is existing post about this problem.

Seitaridis
@Seitaridis: Thanks very much, I did look on here and via Google, but never found anything that did what I wanted
neildeadman