Intelligent Curriculum for Android-dynamic display of dates and times (1)

Source: Internet
Author: User

 

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.