开发者

android local time and timestamp

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜