Here you can find the source of serialize(Instant sourceValue)
public static String serialize(Instant sourceValue)
//package com.java2s; //License from project: Apache License import java.time.*; import java.time.format.DateTimeFormatter; import java.util.Date; public class Main { private static final DateTimeFormatter ISO_DATE_FORMAT_MILLIS = DateTimeFormatter .ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX").withZone(ZoneId.of("UTC")); private static final DateTimeFormatter ISO_DATE_FORMAT_SECONDS = DateTimeFormatter .ofPattern("yyyy-MM-dd'T'HH:mm:ssX").withZone(ZoneId.of("UTC")); private static final DateTimeFormatter ISO_LOCAL_TIME_FORMAT = DateTimeFormatter.ISO_LOCAL_TIME; private static final DateTimeFormatter ISO_LOCAL_FORMAT = DateTimeFormatter.ISO_LOCAL_DATE_TIME; private static final DateTimeFormatter ISO_ZONED_FORMAT = DateTimeFormatter.ISO_ZONED_DATE_TIME; public static String serialize(Instant sourceValue) { if (sourceValue.getNano() == 0) { return ISO_DATE_FORMAT_SECONDS.format(sourceValue); }//from w ww . jav a 2 s.com return ISO_DATE_FORMAT_MILLIS.format(sourceValue); } public static String serialize(LocalDateTime date) { return date.format(ISO_LOCAL_FORMAT); } public static String serialize(ZonedDateTime date) { return date.format(ISO_ZONED_FORMAT); } public static String serialize(LocalTime date) { return date.format(ISO_LOCAL_TIME_FORMAT); } public static String serialize(Date date) { return serialize(fromUtilDate(date)); } public static LocalDateTime fromUtilDate(Date date) { if (date.getClass() == Date.class) { return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); } return fromUtilDate(new Date(date.getTime())); //hack for old java.sql.Date } }