Here you can find the source of formatDateTime(Date dateTime)
public static String formatDateTime(Date dateTime)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static SimpleDateFormat dateSdf = new SimpleDateFormat("yyyyMMdd"); private static SimpleDateFormat dateTimeSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public static String formatDateTime(Date dateTime) { return dateTimeSdf.format(dateTime); }/* www . j a v a 2 s .c om*/ public static String formatDateTime(String dateTime) { return dateTimeSdf.format(parseDate(dateTime)); } public static Date parseDate(String date) { try { return dateSdf.parse(date); } catch (ParseException e) { e.printStackTrace(); } return null; } }