Java tutorial
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static final SimpleDateFormat datetimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public static String formatDatetime(Date date) { return datetimeFormat.format(date); } public static String formatDatetime(Date date, String pattern) { SimpleDateFormat customFormat = (SimpleDateFormat) datetimeFormat.clone(); customFormat.applyPattern(pattern); return customFormat.format(date); } }