Q:

Obtaining the ISO 8601 date format, e.g.: 2009-06-15T13:45:30

How do you format your date in ISO 8601? E.g.: 2009-06-15T13:45:30
Is there a standard way of generating it from Java without having to create a DateTimeFormatter with a letter pattern?
I see it used in MS documentation:
Standard Date and Time Format Strings

A:

I think this is the commonly referred to as "ISO" date.
Documented in wikipedia], giving examples such as:
Date:   2017-02-21
Combined date and time in UTC:  2017-02-21T10:26:42+00:00
                                2017-02-21T10:26:42Z
                                20170221T102642Z

The one thing to be clear: your examples go without any time zone information; so they should be assumed to be "local time".

A:

In this String, T is just Time component in a standard ISO 8601 date time string represented as <date>T<time>. Wikipedia has a detailed page about this standard format.
In java, you can do this to use it
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));

I have used GMT here just for example. You can set the time zone according to your need. To get more information about TimeZone here is the docs link

A:

Easy ways to obtain ISO 8601 in Java:
static void time() {
    final DateTimeFormatter fmt = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
    OffsetDateTime.now().truncatedTo(ChronoUnit.SECONDS).format(fmt);
    Instant.now().atOffset(ZoneOffset.ofHours(1)).truncatedTo(ChronoUnit.SECONDS).format(fmt);
    Instant.now().atOffset(ZoneOffset.UTC).truncatedTo(ChronoUnit.SECONDS).format(fmt);
    OffsetDateTime.parse("2007-12-03T10:15:30+01:00").format(fmt);
    LocalDateTime.parse("2009-06-15T13:45:30").format(fmt);
}

