Java tutorial
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static String getCurrentDateTime() { Calendar c = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss"); String currentDateandTime = sdf.format(new Date(c.getTimeInMillis())); return currentDateandTime; } }