Android Developers: Get method of the current system date and time

The company recently took over the Android project, has been dealing Android App development project, started as a halfway summarizes some Android development experience and knowledge, write it down and then record it to share to people in need to see, then Benpian Bowen came to share in the Android development process, relates to a method to get the current date and time of the system, knowledge is simple, but very practical.

Android get the current system date and time, roughly divided into three ways, as shown below:

A, SimpleDateFormat formatted by the current time acquisition system

Specific code as follows:

SimpleDateFormat formatter = new SimpleDateFormat ( "YYYY-MM-dd HH: mm: ss"); // Set the Time Format

formatter.setTimeZone (. the TimeZone getTimeZone ( "GMT + 08")); // set the time zone

= New new CurDate DATE DATE (the System. With currentTimeMillis ()); // get the current time

String createDate = formatter.format (curDate); // format conversion

 

Second, part of the current through the Calender acquisition system time

Specific code as follows:

. = Calendar Calendar Calendar getInstance (); // get the date when the current time every minute

int year = calendar.get(Calendar.YEAR);

int month = calendar.get(Calendar.MONTH);

int day = calendar.get(Calendar.DAY_OF_MONTH);

int hour = calendar.get(Calendar.HOUR_OF_DAY);

int minute = calendar.get(Calendar.MINUTE);

int second = calendar.get(Calendar.SECOND);

Third, access to the current date and time by Time

Time t = new Time ( "GMT + 8"); // Set Time Zone information.

t.setToNow (); // get the current system time.

int year = t.year;

int month = t.month + 1; // preceded January 1, because the count from zero, and needs an operation

int day = t.monthDay;

int hour = t.hour; // 0-23

int minute = t.minute;

int second = t.second;

These are the entire contents of this chapter, welcomed the focus on three dispensers of public micro-channel number "iOS developed by three dispensers", the three dispensers Weibo "three dispensers 666", please pay attention!

Three dispensers micro-channel public number:

Three dispensers Sina Weibo:

 

Published 224 original articles · won praise 328 · Views 1.08 million +

Guess you like

Origin blog.csdn.net/CC1991_/article/details/103329852