Skip to main content

How to Get Current Date in Android?

In this tutorial i’m going to show you four different ways to get current date in android.

Note : For doing this we will use Calendar, Date, SimpleDateFormate and System class.

Method (1)

This is a first method and in this method we’ll use Calendar and SimpleDateFormate class.

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Calendar c = Calendar.getInstance();
String date = sdf.format(c.getTime());

Method (2)

This is a second method and in this method we’ll use Calendar class to get current date in another way.

Calendar c = Calendar.getInstance();
int day = c.get(Calendar.DAY_OF_MONTH);
int month = c.get(Calendar.MONTH);
int year = c.get(Calendar.YEAR);
String date = day + "/" + (month+1) + "/" + year;

Method (3)

This is a third method and in this method we’ll use Date and SimpleDateFormate class.

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String date = sdf.format(new Date());

Method (4)

This is a final method and in this method we’ll use System and SimpleDateFormate class to get current date.

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String date = sdf.format(System.currentTimeMillis());

Comment below if you know any other way to get current date in android.

Admin

Hi, I am Imran Alam, Full Stack Developer. Helping local businesses to enhance their reach to customers through Websites, Web / Mobile Application, and Digital Marketing. We offer a long range of services like Website Designing, Android Application, School Management System, LMS Software, Point of Sale (Pos) , SEO, Social media Marketing, and Technical Support as well.

Share via
Copy link
Powered by Social Snap