Java ZonedDateTime Calculate canonicalTimeString(ZonedDateTime time)

Here you can find the source of canonicalTimeString(ZonedDateTime time)

Description

ISO8601 can map the same date and time to many different string representations.

License

Apache License

Declaration

public static String canonicalTimeString(ZonedDateTime time) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

public class Main {
    private static DateTimeFormatter canonicalFormatter = DateTimeFormatter
            .ofPattern("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'");

    /**/*from   w  ww  . ja v  a2  s.co  m*/
     * ISO8601 can map the same date and time to many different string
     * representations. This method tries to settle on a sane default (which
     * happens to match Python's default, albeit more because that's convenient
     * than because Python's default is OMG AMAZING).
     */
    public static String canonicalTimeString(ZonedDateTime time) {
        // Target format is "2013-05-27T23:58:20+00:00".
        ZonedDateTime asUTC = time.withZoneSameInstant(ZoneOffset.UTC);
        return asUTC.format(canonicalFormatter);
    }
}

Related

  1. addOffset(ZonedDateTime time, String offset)
  2. addRandomDeltaDays(ZonedDateTime ZDT, int minDays, int maxDays, int minHour, int maxHour)
  3. addRandomDeltaMinutes(ZonedDateTime ZDT, int minMinutes, int maxMinutes)
  4. asZonedDateTime(Date date)
  5. calculateTimeForSunrise(ZonedDateTime from, ZonedDateTime to)
  6. cloneZonedDateTime(ZonedDateTime zonedDateTime)
  7. computeDays(ZonedDateTime Start, ZonedDateTime End)
  8. convertDateToZonedDateTime(Date date, String timezone)
  9. convertForPersistence(@Nullable ZonedDateTime dt)