My date format is yyyy-MM-dd'T'HH:mm:ss.SSSZ, which is producing the date :
2013-10-08T12:14:39.721+0100
But I need the date to be :
2013-10-08T12:14:39.721+01:00
what date format will generate the offset with a colon?
You can use this format
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
Have a look at the doc for more info.
P.S:- As my friend @Thomas mentioned, this will work only with Java 7 and above.
If you want to implement using SimpleDateFormat you can use R.J. solution which will work for JDK 7. You can also implement the same using Joda time as below
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZZ");
String str = fmt.print(dt);
System.out.println(str);
which outputs,
2013-10-08T20:36:19.802+09:00
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With