Returns the current time of the Android system.

Source: Internet
Author: User

Package lyh. demo1; <br/> Import Java. util. calendar; <br/> Import android. app. activity; <br/> Import android. OS. bundle; <br/> Import android. widget. textview; <br/> public class demo1 extends activity {<br/> private textview yeartext; <br/> private textview monthtext; <br/> private textview daytext; <br/> private textview hourtext; <br/> private textview minutetext; <br/> private textview secondtext; </P> <p> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); </P> <p> yeartext = (textview) This. findviewbyid (R. id. year); <br/> monthtext = (textview) This. findviewbyid (R. id. month); <br/> daytext = (textview) This. findviewbyid (R. id. day); <br/> hourtext = (textview) This. findviewbyid (R. id. hour); <br/> minutetext = (textview) This. findviewbyid (R. id. minute); <br/> secondtext = (textview) This. findviewbyid (R. id. second); </P> <p> calendar = calendar. getinstance (); <br/> int year = calendar. get (calendar. year); <br/> int month = calendar. get (calendar. month); <br/> int day = calendar. get (calendar. day_of_month); <br/> int hour = calendar. get (calendar. hour_of_day); <br/> int minute = calendar. get (calendar. minute); <br/> int second = calendar. get (calendar. second); </P> <p> yeartext. settext (string. valueof (year); <br/> monthtext. settext (string. valueof (month); <br/> daytext. settext (string. valueof (day); <br/> hourtext. settext (string. valueof (hour); <br/> minutetext. settext (string. valueof (minute); <br/> secondtext. settext (string. valueof (second); <br/>}< br/>} 

 

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Orientation = "vertical" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> <textview <br/> Android: id = "@ + ID/year" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> <textview <br/> Android: Id = "@ + ID/Month" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> <textview <br/> Android: id = "@ + ID/day" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> <textview <br/> Android: Id = "@ + ID/hour" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> <textview <br/> Android: id = "@ + ID/minute" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> <textview <br/> Android: Id = "@ + ID/second" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> </linearlayout> <br/> 

 

 

 

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.