Here you can find the source of getCurrentDateTime()
public static String getCurrentDateTime()
//package com.java2s; //License from project: Apache License import java.sql.Timestamp; import java.text.SimpleDateFormat; public class Main { private static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss"; private static final String DEFAULT_TIME_PATTERN = "HH:mm:ss"; public static String getCurrentDateTime() { return getCurrentTime(DEFAULT_DATE_PATTERN); }//from w ww . ja v a 2 s . co m public static String getCurrentTime() { return getCurrentTime(DEFAULT_TIME_PATTERN); } public static String getCurrentTime(String format) { SimpleDateFormat sdf = new SimpleDateFormat(format); Timestamp timestamp = new Timestamp(System.currentTimeMillis()); return sdf.format(timestamp); } }