Peter Penzov Peter Penzov - 6 months ago 17
Java Question

Generate date format

I want to generate timestamp using this Java code:

2016-12-25T00:00:00+0530


What mask should I used to get the proper result?

String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());

Answer

Following the SimpleDateFormat Documentation (take a look at the examples) this should give you what you want:

String timeStamp = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss+SSSS").format(new Date());

Edit: If you want the last part to be the time zone offset instead of the milliseconds, you should change the pattern to:

"yyyy-MM-dd'T'HH:mm:ssZ"
Comments