Android.os.SystemClock 介绍

2019-12-23  本文已影响0人  ccbuluo

原文出处:http://www.ccbu.cc/android/android-systemclock

Class Overview

Core timekeeping facilities.

Three different clocks are available, and they should not be confused:

There are several mechanisms for controlling the timing of events(有几种机制控制事件发生的时间):

常用函数

return methods describe
static long currentThreadTimeMillis() Returns milliseconds running in the current thread.
static long elapsedRealtime() Returns milliseconds since boot, including time spent in sleep.
static long elapsedRealtimeNanos() Returns nanoseconds since boot, including time spent in sleep.
static boolean setCurrentTimeMillis(long millis) Sets the current wall time, in milliseconds.
static void sleep(long ms) Waits a given number of milliseconds (of uptimeMillis) before returning.
static long uptimeMillis() Returns milliseconds since boot, not counting time spent in deep sleep.

注释:

1、public static long currentThreadTimeMillis () 返在当前线程运行的毫秒数。

2、public static long elapsedRealtime () 返回系统启动到现在的毫秒数,包含休眠时间。

3、public static long elapsedRealtimeNanos () 返回系统启动到现在的纳秒数,包含休眠时间。

4、public static boolean setCurrentTimeMillis (long millis) 设置当前wall time,要求调用进程有许可权限。返回是否成功。

5、public static void sleep (long ms) 等待给定的时间。和Thread.sleep(millis)类似,但是它不会抛出InterruptedException异常。事件被推迟到下一个中断操作。该方法直到指定的时间过去才返回。

6、public static long uptimeMillis () 返回系统启动到现在的毫秒数,不包含休眠时间。就是说统计系统启动到现在的非休眠期时间。

上一篇 下一篇

猜你喜欢

热点阅读