Convert String timestamp with offset to Java date
I need to convert this timestamp string to Java object Date
2014-04-03T14:02:57.182+0200
How should I do it? How to handle time offset included in a timestamp
+3
user906153
source
to share
2 answers
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);
+3
djm.im
source
to share
Threaded alternative from apache commons lang3. Firstly:
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);
+2
James daily
source
to share