Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display the current time and date in an Android application

How do I display the current date and time in an Android application?

like image 839
BIBEKRBARAL Avatar asked Feb 16 '10 07:02

BIBEKRBARAL


People also ask

Which view is used to display the date and time in Android application?

text. DateFormat. getDateTimeInstance(). format(new Date()); // textView is the TextView view that should display it textView.

How can I get current date and time in Android?

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.

How do you display date and time?

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.


1 Answers

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.

like image 62
Zordid Avatar answered Sep 18 '22 05:09

Zordid