How to get Current System's Time and Date without using Calender.getInstance()
?
To retrieve the current system date and time in local time, use the GetLocalTime function.
Here is the code. . . . public static void getCurrentTimeUsingCalendar() { Calendar cal = Calendar. getInstance(); Date date=cal. getTime(); DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); String formattedDate=dateFormat.
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have given text view, it going to print the current date on the window manager.
Try this:
//-------- Don't know whether this will work on android or not. long dtMili = System.currentTimeMillis(); Date dt = new Date(dtMili);
or
new Date().getTime()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With