[英]Does anyone know how to get the local date and time from Android 2.1 device?
有谁知道如何以编程方式获取Android设备的本地日期和时间? 使用该本地日期和时间,有谁知道如何将其转换为UTC时间中的1970年的毫秒数?
这些只是标准的Java解决方案。 Android独有的功能:
// Get the local date/time
Calendar now = Calendar.getInstance();
// Return milliseconds from 1970 UTC
long milliseconds = now.getTimeInMillis();
如果您只想以毫秒为单位的当前时间戳,则是另一种较短的方法。
很久以前= System.currentTimeMillis();
http://developer.android.com/reference/java/lang/System.html#currentTimeMillis%28%29
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.