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