public final class

SystemClock

extends Object

java.lang.Object
   ↳ android.os.SystemClock

Class Overview


Core timekeeping facilities.

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

  • System.currentTimeMillis() is the standard "wall" clock (time and date) expressing milliseconds since the epoch. The wall clock can be set by the user or the phone network (seesetCurrentTimeMillis(long)), so the time may jump backwards or forwards unpredictably. This clock should only be used when correspondence with real-world dates and times is important, such as in a calendar or alarm clock application. Interval or elapsed time measurements should use a different clock. If you are using System.currentTimeMillis(), consider listening to the ACTION_TIME_TICKACTION_TIME_CHANGED and ACTION_TIMEZONE_CHANGED Intent broadcasts to find out when the time changes.

  • uptimeMillis() is counted in milliseconds since the system was booted. This clock stops when the system enters deep sleep (CPU off, display dark, device waiting for external input), but is not affected by clock scaling, idle, or other power saving mechanisms. This is the basis for most interval timing such as Thread.sleep(millls)Object.wait(millis), and System.nanoTime(). This clock is guaranteed to be monotonic, and is suitable for interval timing when the interval does not span device sleep. Most methods that accept a timestamp value currently expect the uptimeMillis() clock.

  • elapsedRealtime() and elapsedRealtimeNanos() return the time since the system was booted, and include deep sleep. This clock is guaranteed to be monotonic, and continues to tick even when the CPU is in power saving modes, so is the recommend basis for general purpose interval timing.

There are several mechanisms for controlling the timing of events:

Summary


Public Methods
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.
[Expand]

Inherited Methods
 From class java.lang.Object

 

Public Methods


public static long currentThreadTimeMillis ()

Added in API level 1

Returns milliseconds running in the current thread.

Returns
  • elapsed milliseconds in the thread

public static long elapsedRealtime ()

Added in API level 1

Returns milliseconds since boot, including time spent in sleep.

Returns
  • elapsed milliseconds since boot.

public static long elapsedRealtimeNanos ()

Added in API level 17

Returns nanoseconds since boot, including time spent in sleep.

Returns
  • elapsed nanoseconds since boot.

public static boolean setCurrentTimeMillis (long millis)

Added in API level 1

Sets the current wall time, in milliseconds. Requires the calling process to have appropriate permissions.

Returns
  • if the clock was successfully set to the specified time.

public static void sleep (long ms)

Added in API level 1

Waits a given number of milliseconds (of uptimeMillis) before returning. Similar to sleep(long), but does not throw InterruptedExceptioninterrupt() events are deferred until the next interruptible operation. Does not return until at least the specified number of milliseconds has elapsed.

Parameters
ms to sleep before returning, in milliseconds of uptime.

public static long uptimeMillis ()

Added in API level 1

Returns milliseconds since boot, not counting time spent in deep sleep.

Returns
  • milliseconds of non-sleep uptime since boot.

SystemClock官方简介的更多相关文章

  1. 老李推荐:第5章1节《MonkeyRunner源码剖析》Monkey原理分析-启动运行: 官方简介

    老李推荐:第5章1节<MonkeyRunner源码剖析>Monkey原理分析-启动运行: 官方简介   在MonkeyRunner的框架中,Monkey是作为一个服务来接受来自Monkey ...

  2. 第5章1节《MonkeyRunner源码剖析》Monkey原理分析-启动运行: 官方简介(原创)

    天地会珠海分舵注:本来这一系列是准备出一本书的,详情请见早前博文“寻求合作伙伴编写<深入理解 MonkeyRunner>书籍“.但因为诸多原因,没有如愿.所以这里把草稿分享出来,所以错误在 ...

  3. Android4.3引入的UiAutomation新框架官方简介

    译者序:Google在Android 4.3发布时提供了一套新的UiAutomation框架来支持用户界面自动化测试,该框架通过运用已有的Accessibility APIs来模拟用户跟设备用户界面的 ...

  4. 阿里 RocketMQ 安装与简介

    一.简介 官方简介: l  RocketMQ是一款分布式.队列模型的消息中间件,具有以下特点: l  能够保证严格的消息顺序 l  提供丰富的消息拉取模式 l  高效的订阅者水平扩展能力 l  实时的 ...

  5. Hadoop MapReduceV2(Yarn) 框架简介[转]

    对于业界的大数据存储及分布式处理系统来说,Hadoop 是耳熟能详的卓越开源分布式文件存储及处理框架,对于 Hadoop 框架的介绍在此不再累述,读者可参考 Hadoop 官方简介.使用和学习过老 H ...

  6. Hadoop MapReduceV2(Yarn) 框架简介

    http://www.ibm.com/developerworks/cn/opensource/os-cn-hadoop-yarn/ 对于业界的大数据存储及分布式处理系统来说,Hadoop 是耳熟能详 ...

  7. Linux 内存管理之highmem简介

    一.Linux内核地址空间 一般来说Linux 内核按照 3:1 的比率来划分虚拟内存(X86等):3 GB 的虚拟内存用于用户空间,1GB 的内存用于内核空间.当然有些体系结构如MIPS使用2:2 ...

  8. Android Studio重构之路,我们重新来了解一下Google官方的Android开发工具

    Android Studio重构之路,我们重新来了解一下Google官方的Android开发工具 记得我的第一篇博客就是写Android Studio,但是现在看来还是有些粗糙了,所有重构了一下思路, ...

  9. Python【初识篇】简介

    python是什么? 为什么学python? python在权威语言排序网站上的热度 python历史排名 python应用领域 哪些公司在用python python官方简介 上面的话简单的总结来说 ...

随机推荐

  1. asp.net core mvc剖析:mvc执行过程(一)

    前面介绍了路由的过程,我们再来看下MvcRouteHandler的代码: public Task RouteAsync(RouteContext context) { ...... //根据路由信息查 ...

  2. javascript判断浏览器类型与版本

    转自 司徒正美博客: http://www.cnblogs.com/rubylouvre/archive/2009/10/14/1583362.html

  3. jQuery_第一章_JavaScript基础

    JavaScript基础 JavaScript不难,但是对于初学者来讲比较的怪异. 是一种客户端语言,在浏览器执行的.是一种脚本语言,直接就能解释执行的叫脚本代码.像dos命令还有SQL也是. 为什么 ...

  4. [NOI2007]货币兑换Cash(DP+动态凸包)

    第一次打动态凸包维护dp,感觉学到了超级多的东西. 首先,set是如此的好用!!!可以通过控制一个flag来实现两种查询,维护凸包和查找斜率k 不过就是重载运算符和一些细节方面有些恶心,90行解决 后 ...

  5. wikioi 3132 高精度乘法(FFT)

    第一次学FFT,先膜拜一下法法塔大神ORZ 关于FFT的话,有一篇博文特别赞http://z55250825.blog.163.com/blog/static/15023080920143127465 ...

  6. Humble Numbers(丑数) 超详解!

    给定一个素数集合 S = { p[1],p[2],...,p[k] },大于 1 且素因子都属于 S 的数我们成为丑数(Humble Numbers or Ugly Numbers),记第 n 大的丑 ...

  7. Github网站加载不完全,响应超时,如何解决

    Github是一个代码托管平台和开发者社区,开发者可以在Github上创建自己的开源项目并与其他开发者协作编码.毫不夸张地说,高效利用Github是一个优秀的程序员必备的基本素质.可是,有的用户在打开 ...

  8. 【Unity优化】Unity优化技巧进阶开篇

    版权声明:本文为博主原创文章,欢迎转载.请保留博主链接:http://blog.csdn.net/andrewfan 做游戏好多年了,关于游戏优化一直是令开发者头疼的一个问题.因为优化牵扯的内容很多, ...

  9. Laravel Migrate

    artisan命令行创建migrate 格式: php artisan make:migration YourFileName 示例: php artisan make:migration creat ...

  10. WCF小试

    1.创建WCF 右键解决方案-新建项目-WCF服务应用程序. 创建后会生成一些文件,其中IService.cs是服务的接口,只有在接口中定义的方法才能被外部调用,Service.svc是我们的服务名称 ...