How do I display the current date and time in an Android application?
text. DateFormat. getDateTimeInstance(). format(new Date()); // textView is the TextView view that should display it textView.
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.
Time and date ranges For example: 8:00 AM–12:30 PM... To display a date or time range, show an en dash (without spaces) between a range of dates or times. Add spaces when spelling out months, or to remove ambiguity. Use a single AM or PM at the end of the range, if both times have the same AM/PM.
Okay, not that hard as there are several methods to do this. I assume you want to put the current date & time into a TextView
.
String currentDateTimeString = java.text.DateFormat.getDateTimeInstance().format(new Date());
// textView is the TextView view that should display it
textView.setText(currentDateTimeString);
There is more to read in the documentation that can easily be found here . There you'll find more information on how to change the format used for conversion.
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