System.currentTimeMillis()
简介:从1970年1月1日 UTC到如今的毫秒数
返回类型:long
单位:毫秒java
System.nanoTime()
简介:基于cpu核心的时钟周期来计时,它的开始时间是不肯定的,仅可用于比较两个相对时间,运行在两个不一样的cpu核心上,从而致使获得的结果彻底不符逻辑。
返回类型:long
单位:纳秒(1纳秒=0.000001 毫秒,1纳秒=0.00000 0001秒 )post
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 values long 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
单位:毫秒code
SystemClock.elapsedRealtime()
简介从开机到如今的毫秒数(手机睡眠的时间包括在内),AlarmManager能够定时发送消息,即便在系统睡眠、应用中止的状态下也能够发送,这类需求就须要使用该方法
返回类型:long
单位:毫秒it