Android examples for java.util:Date Time
get String Date in yyyy-MM-dd HH:mm:ss format
import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static String getStringDate() { Date currentTime = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); String dateString = formatter.format(currentTime); return dateString; }/*from w w w . j av a 2 s .com*/ public static String getStringDate(String date) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); Date d = new Date(); try { d = formatter.parse(date); } catch (Exception e) { e.printStackTrace(); } String dateString = formatter.format(d); return dateString; } }