Java tutorial
//package com.java2s; import java.util.Calendar; public class Main { /** * Returns current date-time in format of yyyy-MM-dd hh:mm:ss * * @return date time in string. */ public static String getCurrentTime() { int yyyy = Calendar.getInstance().get(Calendar.YEAR); int MM = Calendar.getInstance().get(Calendar.MONTH) + 1; int dd = Calendar.getInstance().get(Calendar.DATE); int hh = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); int mm = Calendar.getInstance().get(Calendar.MINUTE); int ss = Calendar.getInstance().get(Calendar.SECOND); String curDate = String.format("%04d-%02d-%02d %02d:%02d:%02d", yyyy, MM, dd, hh, mm, ss); return curDate; } }