Java tutorial
//package com.java2s; //License from project: LGPL import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; public class Main { public static final String FORMATE_YYYY_MM_DDHHMMSS_FULL = "yyyyMMddHHmmss"; public static String getTimeMillisToFullDate2(long milliSeconds) { Calendar cal = Calendar.getInstance(); java.util.Date currentTime = cal.getTime(); // Create a DateFormatter object for displaying date in specified format. SimpleDateFormat formatter = new SimpleDateFormat(FORMATE_YYYY_MM_DDHHMMSS_FULL); // String ndate = formatter.format(currentTime); // Create a calendar object that will convert the date and time value in milliseconds to date. cal.setTimeInMillis(milliSeconds); return formatter.format(cal.getTime()); } public static String getTime() { return getCurrentDateTime("yyyy-MM-dd HH:mm:ss"); } public static String getCurrentDateTime() { Date today = new Date(); Locale currentLocale = new Locale("KOREAN", "KOREA"); // String pattern = "yyyyMMddHHmmss"; String pattern = "yyyy-MM-dd HH:mm:ss"; // String pattern = "yyyy-MM-dd"; SimpleDateFormat formatter = new SimpleDateFormat(pattern, currentLocale); return formatter.format(today); } public static String getCurrentDateTime(String pattern) { SimpleDateFormat simpleDateFormat = (pattern == null) ? new SimpleDateFormat() : new SimpleDateFormat(pattern); return simpleDateFormat.format(new Date()); } }