1 Package Lianxi;2 3 import Com.example.jichu_lianxi. R;4 5 import android.app.Activity;6 7 import Android.os.Bundle;8 9 import Android.text.format.Time;Ten One import Android.widget.TextView; A import Android.widget.Toast; - - Public classGetTime extends Activity { the - /** Called when the activity is first created.*/ - - @Override + - Public voidonCreate (Bundle savedinstancestate) { + A super.oncreate (savedinstancestate); at - Setcontentview (r.layout.gettime); - -TextView Mytextview =(TextView) Findviewbyid (r.id.gettime); -Time time =NewTime ("gmt+8"); - Time.settonow (); in intYear = Time.year;//Get year - intmonth = Time.month;//Get Month to intDay = Time.monthday;//get the day number + inthour = Time.hour;//get the hours, note that the hour here is 24-made - intminute = Time.minute;//Get minutes the intSEC = Time.second;//Get seconds *String time_s ="The current time is:"+ year +"years"+ Month +"Month"+ Day +"Day"+ Hour +"when"+ Minute +"points"+ sec +"seconds"; $Toast.maketext (GetTime. This, time_s, Toast.length_short). Show ();Panax Notoginseng - the } + A}
The second method:
Package Lianxi;import Com.example.jichu_lianxi. R;import android.app.Activity; Import Android.os.Bundle; Import Android.text.format.Time; Import Android.widget.TextView; Import Android.widget.Toast; Public classGetTime extends Activity {/** Called when the activity is first created.*/@Override Public voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.gettime); Calendar C=calendar.getinstance (); intYear = c.Get(calendar.year); Get yearintmonth = c.Get(Calendar.month); Get MonthintDay = c.Get(Calendar.day_of_month); Get Dateinthour = c.Get(Calendar.hour_of_day); Get hoursintminute = c.Get(Calendar.minute);//Get minutes
String time_s ="The current time is:"+ year +"years"+ Month +"Month"+ Day +"Day"+ Hour +"when"+ Minute +"points";
Toast.maketext (GetTime. This, time_s, Toast.length_short). Show ();} }
:
Refer to http://www.01yun.com/mobile_development/20130425/378941.html (reprint please specify)
About Android start to achieve the simplest time to get the system