开发者

android local time and timestamp

开发者 https://www.devze.com 2023-02-19 19:03 出处:网络
hi 开发者_Go百科to all how can i get the currant time and date for android and compare it with a timestamp i haveCurrent Timestamp (Milliseconds)

hi 开发者_Go百科to all how can i get the currant time and date for android and compare it with a timestamp i have


Current Timestamp (Milliseconds)

long currentTimestamp = System.currentTimeMillis()

http://developer.android.com/reference/java/lang/System.html#currentTimeMillis()


The reference page you want is Android SystemClock. It recommends using either uptimeMillis or elapsedRealtime, depending on whether your app needs to count time during deep sleep or not.

long etime = 0;
final long time1 = uptimeMillis();
/* do something */
final long time2 = uptimeMillis();
if (time2 < time1) {
    etime = Long.MAX_VALUE - time1 + time2;
} else {
    etime = time2 - time1;
}

Note: the value returned can wrap because long isn't infinite; check for a negative value as above.

0

精彩评论

暂无评论...
验证码 换一张
取 消