Starting from today, we will step by step implement what we want to achieve in demand analysis. First, we will achieve dynamic display of the date and time at the top of the curriculum.
The date is automatically updated every day, and the time is dynamically changed in seconds.
There are two classes for processing java time and Date: Date () and Calendar (). Since the Date and time are processed from java, it is recommended that you use Calendar () so here we use the Calendar () class to process the time and date.
GetTime ()
GetTime
Public final Date getTime ()
Returns a Date object that represents the Calendar time value (offset from the Calendar element to the current millisecond.
Return Value:
Indicates the Date of the time value.
For more information, see:
SetTime (Date), getTimeInMillis ()
Write code,
Time = Calendar. getInstance (). getTime (). toString ();
Textview01.setText (time );
Run in the simulator to obtain
We can see that the displayed date is the default display method, so how can we change the date format to our common display method.
Use the query API to find the SimpleDateFormat class that changes the date and time format
Public class SimpleDateFormat
Extends DateFormat
SimpleDateFormat is a specific class related to the language environment to format and parse dates. It allows formatting (date-> text), parsing (text-> date), and normalization.
Private String DEFAULT_TIME_FORMAT = "yyyy-MM-dd hh: mm: ss ";
SimpleDateFormat dateFormatter = new SimpleDateFormat (DEFAULT_TIME_FORMAT );
Time = dateFormatter. format (Calendar. getInstance (). getTime ());
Textview01.setText (time );
Run in the simulator to obtain
However, the current display is static and cannot be changed dynamically. Next time, we will change the date and time dynamically.
From the tianshuguang Column