Android files are recommended to replace calendar with time. The load on the CPU with time is small. is especially important when writing widgets.
Time T=new time (); or time T=new time ("gmt+8"); Add time zone information.
[Java]View Plaincopy
- Package itokit.com;
- Import android.app.Activity;
- Import Android.os.Bundle;
- Import Android.text.format.Time;
- Import Android.widget.TextView;
- Public class ShowTime extends Activity {
- /** Called when the activity is first created. * /
- @Override
- public void OnCreate (Bundle savedinstancestate) {
- super.oncreate (savedinstancestate);
- Setcontentview (R.layout.main);
- TextView Mytextview = (TextView) Findviewbyid (R.id.mytextview);
- Time time = new Time ("gmt+8");
- Time.settonow ();
- int year = Time.year;
- int month = Time.month;
- int day = Time.monthday;
- int minute = Time.minute;
- int hour = Time.hour;
- int sec = Time.second;
- Mytextview.settext ("Current time:" + year +
- "Year" + month +
- "Month" + Day +
- "Day" + Hour +
- "when" + Minute +
- "min" + sec +
- "seconds");
- }
- }
The only disadvantage is that the removal time is only 24 hours mode.
Long Time=system.currenttimemillis ();
Final Calendar mcalendar=calendar.getinstance ();
Mcalendar.settimeinmillis (time);
Hours of acquisition: Mhour=mcalendar.get (Calendar.hour);
Get minutes: Mminuts=mcalendar.get (Calendar.minute);
How to get the Android system time is 24 hour or 12 hour system
Contentresolver CV = this.getcontentresolver ();
String Strtimeformat = android.provider.Settings.System.getString (CV,
ANDROID.PROVIDER.SETTINGS.SYSTEM.TIME_12_24);
if (Strtimeformat.equals ("24"))
{
LOG.I ("Activity", "24");
}
Calendar C = calendar.getinstance ();
Get system date: Year = C.get (calendar.year)
month = C.GRT (calendar.month)
Day = C.get (calendar.day_of_month)
Acquisition system time: Hour = C.get (Calendar.hour_of_day);
minute = C.get (Calendar.minute)
use calendar to get
Calendar C = calendar.getinstance ();
Get system date: Year = C.get (calendar.year)
month = C.GRT (calendar.month)
Day = C.get (calendar.day_of_month)
Acquisition system time: Hour = C.get (Calendar.hour_of_day);
minute = C.get (Calendar.minute)
Calendar C = calendar.getinstance ();
Get system date: Year = C.get (calendar.year)
month = C.GRT (calendar.month)
Day = C.get (calendar.day_of_month)
Acquisition system time: Hour = C.get (Calendar.hour_of_day);
minute = C.get (Calendar.minute)
Get Date and time