Reputation: 1218
I need to convert this timestamp string to a Java Date
object
2014-04-03T14:02:57.182+0200
How do I do this? How do I handle the time offset included in the timestamp
Upvotes: 3
Views: 1938
Reputation: 597
Thread-safe alternative from apache commons lang3. First:
import org.apache.commons.lang3.time.FastDateFormat;
then:
String strdate = "2014-04-03T14:02:57.182+0200";
String dateFormatPattern = "yyyy-mm-dd'T'HH:mm:ss.SSSZ";
Date date = FastDateFormat.getInstance(dateFormatPattern).parse(strdate);
System.out.println(date);
Upvotes: 2
Reputation: 3323
You can use this code:
String strdate = "2014-04-03T14:02:57.182+0200";
Date date = new SimpleDateFormat("yyyy-mm-dd'T'HH:mm:ss.SSSZ").parse(strdate);
System.out.println(date);
Upvotes: 3