Android – Get current date and time in different format

By -

Related Article: Get current date and time. But this article guides you to fetch current date and time in different formats. Just define your SimpleDateFormat object with desired format and format the current date and time by using format() method.

Calendar c = Calendar.getInstance();
System.out.println("Current time => " + c.getTime());

SimpleDateFormat df1 = new SimpleDateFormat("dd-MMM-yyyy");
String formattedDate1 = df1.format(c.getTime());

SimpleDateFormat df2 = new SimpleDateFormat("dd-MM-yyyy");
String formattedDate2 = df2.format(c.getTime());

SimpleDateFormat df3 = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss a");
String formattedDate3 = df3.format(c.getTime());

System.out.println("=========> Date 1 => "+formattedDate1);
System.out.println("=========> Date 2 => "+formattedDate2);
System.out.println("=========> Date 3 => "+formattedDate3);


Paresh Mayani

Lazy android developer, exploring the horizon of android development since 7 years, currently working as a Technical Lead - Android at Simform Solutions, India. Former Application Architect at KarConnect. He is the Head/Organizer of Google Developers Group (GDG), Ahmedabad

Loading Facebook Comments ...
Loading Disqus Comments ...