Here you can find the source of formatInstant(TemporalAccessor instant)
Parameter | Description |
---|---|
instant | The instant to represent as ISO8601 data |
public static String formatInstant(TemporalAccessor instant)
//package com.java2s; /*// w w w. j av a2s . c o m * Copyright (c) 2010-2017. Axon Framework * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; import java.time.format.SignStyle; import java.time.temporal.TemporalAccessor; import static java.time.temporal.ChronoField.*; public class Main { private static final DateTimeFormatter ISO_UTC_DATE_TIME = new DateTimeFormatterBuilder().parseCaseInsensitive() .appendValue(YEAR, 4, 10, SignStyle.EXCEEDS_PAD).appendLiteral('-').appendValue(MONTH_OF_YEAR, 2) .appendLiteral('-').appendValue(DAY_OF_MONTH, 2).appendLiteral('T').appendValue(HOUR_OF_DAY, 2) .appendLiteral(':').appendValue(MINUTE_OF_HOUR, 2).appendLiteral(':').appendValue(SECOND_OF_MINUTE, 2) .appendFraction(NANO_OF_SECOND, 3, 9, true).appendOffsetId().toFormatter().withZone(ZoneOffset.UTC); /** * Formats the given instant to ISO8601 format including at least 3 positions for milliseconds. This is to provide * for a String representation of an instant that is sortable by a textual sorting algorithm. * * @param instant The instant to represent as ISO8601 data * @return The ISO8601 representation of the instant in the UTC timezone. */ public static String formatInstant(TemporalAccessor instant) { return ISO_UTC_DATE_TIME.format(instant); } }