Java Instant Format format(Instant _instant, String _format)

Here you can find the source of format(Instant _instant, String _format)

Description

Return a string from Instant using format _format

License

Open Source License

Parameter

Parameter Description
_instant a parameter

Declaration

public static final String format(Instant _instant, String _format) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.time.DateTimeException;
import java.time.Instant;

import java.time.LocalDateTime;

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

public class Main {
    public static final ZoneOffset localZoneOffset = ZoneOffset.UTC;

    /**/*from   w w w  .  ja va2s  .c om*/
     * Return a string from Instant using format _format
     * @param _instant
     */
    public static final String format(Instant _instant, String _format) {
        DateTimeFormatter format = DateTimeFormatter.ofPattern(_format);

        try {
            return LocalDateTime.ofInstant(_instant, localZoneOffset).format(format);
        } catch (DateTimeException exc) {
            System.out.printf("%s can't be formatted with pattern!%n", _instant, _format);
            throw exc;
        }
    }
}

Related

  1. format(Instant instant)
  2. formatAtSAST(Instant instant, DateTimeFormatter format)
  3. formatDate(Instant date, Locale locale)
  4. formatDateForInstant(Instant instant)