how to get current date and time in android studio
MainActivity.java
// get current date in 03-01-2020 format
String currentDate = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).format(new Date());
// get current date in 03-Jan-2020 format
String currentDate2 = new SimpleDateFormat("dd-MMM-yyyy", Locale.getDefault()).format(new Date());
// get day name like Mon, Tue, Wed, etc.
String dayName = new SimpleDateFormat("E", Locale.getDefault()).format(new Date());
// get time in 12 hours
String getTime = new SimpleDateFormat("hh:mm:ss a", Locale.getDefault()).format(new Date());
// get time in 24 hours
String getTime2 = new SimpleDateFormat("HH:mm:ss", Locale.getDefault()).format(new Date());
// get both date and time
String currentDateTime = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss", Locale.getDefault()).format(new Date());
Projects with Source Code + Video Tutorials
You can download our Java and Android Studio Projects with Source Code and Video Tutorials.
Login and Register using Firebase Realtime Database
Gamer Bazi - Tournament Application with Admob Ads & Web Admin Panel
Login & Register Screen UI Design - 02
If you have any Questions or Queries
You can mail us at info.learnoset@gmail.com
Follow us to learn Coding and get in touch with new Technologies.