时间间隔: SystemClock.uptimeMillis与System.currentTimeMillis
2016-06-14 12:30
441 查看
很多情况下,不管是我们自己使用时间间隔来做一些算法,或是调用系统的API,比如动画效果,都会需要基于时间间隔来做,通常做法是:记录开始时间 startTime,然后每次回调时,获取当前时间 currentTime,计算差值 = currentTime
- startTime,而获取当前时间,系统提供了两种方法:
SystemClock.uptimeMillis 和 System.currentTimeMillis
这两种方法有何区别呢?
1. SystemClock.uptimeMillis() // 从开机到现在的毫秒数(手机睡眠的时间不包括在内);
2. System.currentTimeMillis() // 从1970年1月1日 UTC到现在的毫秒数;
但是,第2个时间,是可以通过System.setCurrentTimeMillis修改的,那么,在某些情况下,一但被修改,时间间隔就不准了。
特别说明点:AnimationUtils 中明确说了:
[java]
/**
* Returns the current animation time in milliseconds.
* This time should be used when invoking
* {@link Animation#setStartTime(long)}. Refer to
* {@link android.os.SystemClock} for more
* information about the different available clocks.
* The clock used by this method is
* <em>not</em> the "wall" clock (it is not
* {@link System#currentTimeMillis}).
*
* @return the current animation time in milliseconds
*
* @see android.os.SystemClock
*/
- startTime,而获取当前时间,系统提供了两种方法:
SystemClock.uptimeMillis 和 System.currentTimeMillis
这两种方法有何区别呢?
1. SystemClock.uptimeMillis() // 从开机到现在的毫秒数(手机睡眠的时间不包括在内);
2. System.currentTimeMillis() // 从1970年1月1日 UTC到现在的毫秒数;
但是,第2个时间,是可以通过System.setCurrentTimeMillis修改的,那么,在某些情况下,一但被修改,时间间隔就不准了。
特别说明点:AnimationUtils 中明确说了:
[java]
/**
* Returns the current animation time in milliseconds.
* This time should be used when invoking
* {@link Animation#setStartTime(long)}. Refer to
* {@link android.os.SystemClock} for more
* information about the different available clocks.
* The clock used by this method is
* <em>not</em> the "wall" clock (it is not
* {@link System#currentTimeMillis}).
*
* @return the current animation time in milliseconds
*
* @see android.os.SystemClock
*/
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories