4 Ways to Get Current Date in Android

In this tutorial I will show you 4 different ways to get current date in android.

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

How to Get Current Date in Android?

Method 1:

In this method we will use Calendar and SimpleDateFormate class.

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

 

Method 2:

We can 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:

In this method we will use Date and SimpleDateFormate class.

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

 

Method 4:

Another method in which we will 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.

2 thoughts on “4 Ways to Get Current Date in Android”

Leave a Comment

Your email address will not be published. Required fields are marked *