Java tutorial
//package com.java2s; import java.text.DecimalFormat; import java.util.Calendar; public class Main { public static String getCurrentTime() { DecimalFormat df = new DecimalFormat("00"); Calendar c = Calendar.getInstance(); String currentTime = c.get(Calendar.YEAR)// + "-" + df.format((c.get(Calendar.MONTH) + 1)) // + "-" + df.format(c.get(Calendar.DAY_OF_MONTH))// + "-" + df.format(c.get(Calendar.HOUR_OF_DAY)) // + "-" + df.format(c.get(Calendar.MINUTE))// + "-" + df.format(c.get(Calendar.SECOND)); return currentTime; } }