I got a date 2014-01-01T01:14:48.000+08:00
from a web server. Does anyone know how to parse this correctly? How to get its time offset
?
Asked
Active
Viewed 75 times
-2

liminche
- 261
- 1
- 6
- 13
-
You mean parse? or format? or reformat? What is your expected output? – Adam Jun 23 '15 at 06:05
-
Use SimpleDateFormat to parse that Date and then use a Calendar to get the timeOffset – Jens Jun 23 '15 at 06:06
-
This type of format is called ISO 8601, google has plenty of answers...http://stackoverflow.com/questions/2201925/converting-iso-8601-compliant-string-to-java-util-date – Adam Jun 23 '15 at 06:18
-
yes, parse this date – liminche Jun 23 '15 at 06:40
2 Answers
1
String s="2014-01-01T01:14:48.000+08:00";
SimpleDateFormat sdf=new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
System.out.println(sdf.format(s));

Chandu D
- 505
- 3
- 17
-
-
This doesn't work: java.lang.IllegalArgumentException: Cannot format given Object as a Date – Adam Jun 23 '15 at 06:17
0
You need something like this,
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSX");
System.out.println(sdf.parse(y));
The X
is for timezone.

Codebender
- 14,221
- 7
- 48
- 85