Wednesday, June 5, 2019

How to get current time and date in Android



How to get the current time and date in an Android App?


Answer



You could use:



import java.util.Calendar

Date currentTime = Calendar.getInstance().getTime();




output - Thu Dec 19 18:53:43 GMT+05:30




SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault());

//You can change "yyyyMMdd_HHmmss as per your requirement


String currentDateandTime = sdf.format(new Date());



Output - 20191219_185343




There are plenty of constants in Calendar for everything you need.



Edit:
Check Calendar class documentation



No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...