TL; DR
ZonedDateTime zdt = ZonedDateTime.now( ZoneId.of( "America/Chicago" ) ) ; String output = zdt.toInstant().toString() ;
2016-12-03T10: 15: 30z
java.time
Both the java.util.Calendar classes and the Joda-Time library were superseded by the java.time classes.
Instant
Instant class represents a moment on the timeline in UTC with a resolution of nanoseconds .
Instant instant = Instant.now();
Call toString to generate a string in the standard ISO 8601 format . For example, 2011-12-03T10:15:30Z . This format is good for serializing date and time values ββfor storing or exchanging data.
String output = instant.toString();
Timezone
Set the time zone.
ZoneId z = ZoneId.of( "America/Chicago" ); ZonedDateTime zdt = instant.atZone( z );
As a shortcut, you can skip using Instant .
ZonedDateTime zdt = ZonedDateTime.now( z );
Calling toString on ZonedDateTime provides you with an extended version of the standard ISO 8601 format, where the time zone name is added in square brackets. For example, 2007-12-03T10:15:30+01:00[Europe/Paris] .
String output = zdt.toString();
DateTimeFormatter
The DateTimeFormatter class has a predefined formatting constant for the desired result: DateTimeFormatter.ISO_LOCAL_DATE_TIME
String output zdt.format( DateTimeFormatter.ISO_LOCAL_DATE_TIME );
About java.time
The java.time framework is built into Java 8 and later. These classes supersede the nasty old legacy time classes such as java.util.Date , Calendar and SimpleDateFormat .
The Joda-Time project, now in maintenance mode , we recommend switching to the java.time classes.
To learn more, see the Oracle Tutorial . And search for qaru for many examples and explanations. JSR 310 specification .
With a JDBC driver corresponding to JDBC 4.2 or later, you can exchange java.time objects directly with your database. No need for strings or java.sql. * Classes.
Where to get java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is proof of possible future additions to java.time. Here you can find useful classes such as Interval , YearWeek , YearQuarter and more .