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. css居中问题

    学习过程中遇到css居中问题 , 也查阅了资料,每个人的方法都不尽相同,而且当时看懂了,过后就记混淆了;so作为一个前端小白,也来写一下俗话说好脑子不如烂笔头,毕竟自己知道的也不多,其实是抱着学习和交 ...

  2. 每天一个linux命令(32)--/etc/group文件详解

    Linux /etc/group 文件与 /etc/passwd 和/etc/shadow 文件都是有关于系统管理员对用户和用户组管理时相关的文件.Linux /etc/group 文件是有关于系统管 ...

  3. 原生js和jquery实现图片轮播特效(转)

    本文给大家分享的是使用原生JS和JQ两种方法分别实现相同的图片轮播特效,十分的实用,也非常方便大家对比学习原生js和jQuery,有需要的小伙伴可以参考下. 1)首先是页面的结构部分对于我这种左右切换 ...

  4. 第22篇 js中的this指针的用法

    前面把js的相关知识总结了下,今天把js中的上下文的this,对于强类型语言,this的用法非常的单一,因为他们没有js特有的动态绑定. 首先看下面代码: function funcA() { thi ...

  5. 数据存储与访问之——初见SQLite数据库

          本节引言: 本节学习Android数据库存储与访问的第三种方式:SQLite数据库,和其他的SQL数据库不同,我们并不需要在手机上另外安装一个数据库手机软件,Android系统已经集成了这 ...

  6. x86主机搭建家庭智能路由系统 ---- 设计篇

    组件简介 Proxmox: 基于Debian的虚拟化系统,支持OpenVZ和KVM. pfSense: 基于FreeBSD的开源路由系统. FreeNAS: 开源NAS系统. shadowsocks: ...

  7. MySQL索引的使用方式

    一,create CREATE INDEX可对表增加普通索引或UNIQUE索引. CREATE INDEX index_name ON table_name (column_list) CREATE ...

  8. Jemter+Badboy实战经验一(Badboy录制及基础功能)

    1. 使用工具: Apache Jemeter:http://jmeter.apache.org/download_jmeter.cgi (免费官网下载地址) BadBoy:   http://www ...

  9. 服务器数据库搭建流程(CentOs+mysql)

    前言: 服务器上数据库搭建需要知道Linux系统的版本,以前的Ubuntu14.04直接在终端下输入apt-get install (package)便可方便的下载并安装mysql,但是在centOs ...

  10. 每天一个Linux命令 4

    Linux系统关机命令 shutdown -h 时间 init 0 poweroff Linux系统注销命令 logout 或者是快捷键 Ctrl+d Linux系统重启命令 reboot Linux ...