2019独角兽企业重金招聘Python工程师标准>>>
-
System.currentTimeMillis()
简介:从1970年1月1日 UTC到现在的毫秒数
返回类型:long
单位:毫秒 -
System.nanoTime()
简介:基于cpu核心的时钟周期来计时,它的开始时间是不确定的,仅可用于比较两个相对时间,运行在两个不同的cpu核心上,从而导致得到的结果完全不符逻辑。
返回类型:long
单位:纳秒(1纳秒=0.000001 毫秒,1纳秒=0.00000 0001秒 )
For example, to measure how long some code takes to execute:long startTime = System.nanoTime();// ... the code being measured ...long estimatedTime = System.nanoTime() - startTime;To compare two nanoTime valueslong t0 = System.nanoTime();...long t1 = System.nanoTime();one should use {@code t1 - t0 < 0}, not {@code t1 < t0},because of the possibility of numerical overflow.
-
SystemClock.uptimeMillis()
简介:从开机到现在的毫秒数(手机睡眠的时间不包括在内),Handler类的 postDelay()方法也是基于SystemClock.upTimeMillis()方法
返回类型:long
单位:毫秒 -
SystemClock.elapsedRealtime()
简介从开机到现在的毫秒数(手机睡眠的时间包括在内),AlarmManager可以定时发送消息,即使在系统睡眠、应用停止的状态下也可以发送,这类需求就需要使用该方法
返回类型:long
单位:毫秒