Here you can find the source of getFormattedDateTime(Date date, String pattern)
public static String getFormattedDateTime(Date date, String pattern)
//package com.java2s; /*//from ww w. ja v a 2 s . c om * Copyright (c) 2015, Anshoo Arora (Relevant Codes). All rights reserved. * * Copyrights licensed under the New BSD License. * * See the accompanying LICENSE file for terms. */ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static String getFormattedDateTime(Date date, String pattern) { SimpleDateFormat sdfDate = new SimpleDateFormat(pattern); return sdfDate.format(date); } public static String getFormattedDateTime(String dateTime, String pattern) { SimpleDateFormat sdfDate = new SimpleDateFormat(pattern); DateFormat format = new SimpleDateFormat(pattern, Locale.ENGLISH); Date date; try { date = format.parse(dateTime); return sdfDate.format(date); } catch (ParseException e) { return dateTime; } } public static String getFormattedDateTime(long millis, String pattern) { SimpleDateFormat sdfDate = new SimpleDateFormat(pattern); Date date = new Date(millis); return sdfDate.format(date); } }