Peter Penzov Peter Penzov - 1 year ago 117
Java Question

Generate date format

I want to generate timestamp using this Java code:


What mask should I used to get the proper result?

String timeStamp = new SimpleDateFormat("").format(new Date());

Answer Source

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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download