Java Instant Format formatDateForInstant(Instant instant)

Here you can find the source of formatDateForInstant(Instant instant)

Description

format Date For Instant

License

Open Source License

Declaration

public static String formatDateForInstant(Instant instant) 

Method Source Code


//package com.java2s;
/*//www . j av a2 s . co  m
 * Copyright (C) 2014-2015 ULYSSIS VZW
 *
 * This file is part of i++.
 * 
 * i++ is free software: you can redistribute it and/or modify
 * it under the terms of version 3 of the GNU Affero General Public License
 * as published by the Free Software Foundation. No other versions apply.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>
 */

import java.time.DateTimeException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

public class Main {
    public static String formatDateForInstant(Instant instant) {
        try {
            LocalDateTime localDate = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MMMM yyyy");
            return localDate.format(formatter);
        } catch (DateTimeException ignored) {
            return "N/A";
        }
    }
}

Related

  1. format(Instant _instant, String _format)
  2. format(Instant instant)
  3. formatAtSAST(Instant instant, DateTimeFormatter format)
  4. formatDate(Instant date, Locale locale)
  5. formatHttpDate(Instant instant)
  6. formatInstant(TemporalAccessor instant)
  7. formatIso8601Date(Instant date)
  8. formatTimeLocal(Instant instant)