Java DateTimeFormatter formatDate(long date)

Here you can find the source of formatDate(long date)

Description

format Date

License

Open Source License

Declaration

public static String formatDate(long date) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014,2015 Hideki Yatomi
 * All rights reserved. This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/

import java.time.*;
import java.time.format.*;
import java.util.*;

public class Main {
    private static DateTimeFormatter dateTimeFormatter;

    public static String formatDate(long date) {
        if (dateTimeFormatter == null)
            dateTimeFormatter = DateTimeFormatter
                    .ofPattern("yyyy/MM/dd HH:mm:ss");
        return LocalDateTime.ofInstant(new Date().toInstant(),
                ZoneId.systemDefault()).format(dateTimeFormatter);
    }//w w  w. ja  va 2 s .com
}

Related

  1. dateTimeFormatterNCForPattern(String pattern)
  2. format(DateTimeFormatter formatter, Object object)
  3. format(long epochMilliSecond)
  4. formatAgo(long timestamp)
  5. formatByLocale(Date date, Locale locale)
  6. formatDate(long milli)
  7. formatDate(long timestamp)
  8. formatDate(long timestamp)
  9. formatDateAndTime(String dateAndTime)