简体   繁体   English

有谁知道如何从Android 2.1设备获取本地日期和时间?

[英]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? 有谁知道如何以编程方式获取Android设备的本地日期和时间? With that local date and time, does anyone know how to convert that to milliseconds from 1970 in UTC time? 使用该本地日期和时间,有谁知道如何将其转换为UTC时间中的1970年的毫秒数?

These are just standard Java solutions; 这些只是标准的Java解决方案。 nothing unique to Android: 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(); 很久以前= System.currentTimeMillis();

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有谁知道如何从 java 的记录中提取日期? - Does anyone know how to extract a date from a record in java? 如果未启用自动时钟,如何知道本地时间与 android 设备之间的时差? 我以编程方式需要它 - How to know time difference between the local time and the android device if the auto clock is not enabled ? I need it programmatically 如何从互联网或服务器获取日期和时间而不是从我的 android 设备 - How Get Date And Time from internet or server not from my android device 有谁知道如何提取我的日期字符串并更改格式? - Does anyone know how extract my date string & change the format? 如何获取Android设备打开时间的日期? - How can i get a date of android device opening time? 有人知道如何在Android Studio中使用Expression吗? - Does anyone know how to use Expression in Android Studio? 有谁知道如何摆脱这个日食错误窗口? - Does anyone know how to get rid of this eclipse error window? 设备离线时如何获取 android 设备的正确当前日期和时间 - How can I get correct current date and time for android device while device is offline 在Android系统中,对于日期和时间的每一次变化,有没有办法知道用户是否提前或延迟了设备时间或日期? - In Android system, for every change in date and time, is there a way to know if the user has advanced or delayed the device time or date? 设备长时间休眠时Android是否会删除局部变量? - Does Android delete local variables when the device is in sleep for a long time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM