Java Datetime with Timezone format

datetime, java, timezone

Solution

Have a look at the API documentation of SimpleDateFormat. There you can see, that you can use the character 'z' for the timezone information.

Example: "yyyy.MM.dd G 'at' HH:mm:ss z" will give you "2001.07.04 AD at 12:08:56 PDT"

To set the timezone on a date have a look at this question and the answers.

Problem

I am currently using `SimpleDateFormat` to create a datetime value in the format `yyyy-MM-dd HH:mm:ss`. Here is my code: ``` Date date = new SimpleDateFormat("yy-M-d H:m:ss").parse(datetime); String Dtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date); ``` However I would like the format to be this instead: ``` 2013-04-12T13:38:48+02:00 ``` How can I add the timezone to get the desired format? Thank you!

Original source

Related problems