简体   繁体   中英

Does anyone know how to get the local date and time from Android 2.1 device?

Does anyone know know how to programatically get the local date and time of the Android device? With that local date and time, does anyone know how to convert that to milliseconds from 1970 in UTC time?

These are just standard Java solutions; nothing unique to Android:

// Get the local date/time
Calendar now = Calendar.getInstance();

// Return milliseconds from 1970 UTC
long milliseconds = now.getTimeInMillis();

Another shorter way, if you just want the current timestamp in millis.

long now = System.currentTimeMillis();

http://developer.android.com/reference/java/lang/System.html#currentTimeMillis%28%29

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM