Java DateTimeFormatter getFormatDate(String format)

Here you can find the source of getFormatDate(String format)

Description

get Format Date

License

Open Source License

Declaration

public static String getFormatDate(String format) 

Method Source Code


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

import java.time.*;
import java.time.format.DateTimeFormatter;

import java.util.Date;

public class Main {

    public static String getFormatDate(String format) {
        return getFormatDate(format, new Date());
    }//from  w ww. java 2  s .co  m

    public static String getFormatDate(String format, String zoneId) {
        return getFormatDate(format, new Date(), zoneId);
    }

    public static String getFormatDate(String format, Date date) {
        return getFormatDate(format, date, ZoneId.systemDefault().getId());
    }

    public static String getFormatDate(String format, Date date, String zoneId) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(format);
        return dateTimeFormatter.format(date.toInstant().atZone(ZoneId.of(zoneId)).toLocalDateTime());
    }
}

Related

  1. getDateFormat()
  2. getDateFormat(final Locale LOCALE)
  3. getDateFromFormat(String dtStr)
  4. getDateTimeAttributeTimeFormat()
  5. getDateTimeFormatter()
  6. getFormattedDate()
  7. getFormattedDateString()
  8. getFullFormatter()
  9. getGermanFormatter()