Here you can find the source of getFormatDate(String format)
public static String getFormatDate(String format)
//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()); } }