[英]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.