Java tutorial
//package com.java2s; import java.sql.Timestamp; import java.text.SimpleDateFormat; public class Main { public static Timestamp now() { return new Timestamp(System.currentTimeMillis()); } public static String now(String pattern) { return TimestampToString(now(), pattern); } public static String TimestampToString(Timestamp timestamp, String pattern) { SimpleDateFormat df = new SimpleDateFormat(pattern); try { return df.format(timestamp); } catch (Exception e) { return ""; } } }