public class Time extends Object
Time objects used for obtaining and setting the system time and time zone.
This class can be used to obtain the system time, system uptime (including or excluding deep sleep time), thread uptime, and the system time zone.
Obtain the SystemPermission#SET_TIME permission to set system time.
Obtain the SystemPermission#SET_TIME_ZONE permission to set the system time zone.
SystemCapability.Miscservices#TIME| 构造器 | 说明 |
|---|---|
Time() |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static long |
getCurrentThreadTime() |
Obtains the number of milliseconds elapsed in the current thread.
|
static long |
getCurrentThreadTimeNs() |
Obtains the number of nanoseconds elapsed in the current thread.
|
static long |
getCurrentTime() |
Obtains the number of milliseconds that have elapsed since the Unix epoch.
|
static long |
getCurrentTimeNs() |
Obtains the number of nanoseconds that have elapsed since the Unix epoch.
|
static long |
getRealActiveTime() |
Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time.
|
static long |
getRealActiveTimeNs() |
Obtains the number of nanoseconds elapsed since the system was booted, not including deep sleep time.
|
static long |
getRealTime() |
Obtains the number of milliseconds elapsed since the system was booted, including deep sleep time.
|
static long |
getRealTimeNs() |
Obtains the number of nanoseconds elapsed since the system was booted, including deep sleep time.
|
static String |
getTimeZone() |
Obtains the system time zone.
|
static long |
setTime(Context context,
long time) |
Sets the system time.
|
static long |
setTime(Context context,
Date date) |
Sets the system time.
|
static long |
setTimeZone(Context context,
String timezone) |
Sets the system time zone.
|
static void |
sleep(long milliSecond) |
Waits a specified number of milliseconds before returning.
|
public static long getCurrentTime()
public static long getCurrentTimeNs()
public static long getRealActiveTime()
public static long getRealActiveTimeNs()
public static long getRealTime()
public static long getRealTimeNs()
public static long getCurrentThreadTime()
public static long getCurrentThreadTimeNs()
public static long setTime(Context context, long time)
To use this method, obtain the SystemPermission#SET_TIME permission.
context - Indicates the application context used for permission verification.time - Indicates a timestamp to set.0 if the time is set; returns a negative number otherwise.public static long setTime(Context context, Date date)
To use this method, obtain the SystemPermission#SET_TIME permission.
context - Indicates the application context used for permission verification.date - Indicates a Date object to set.0 if the time is set; returns a negative number otherwise.public static String getTimeZone()
public static long setTimeZone(Context context, String timezone)
To use this method, obtain the SystemPermission#SET_TIME_ZONE permission.
context - Indicates the application context used for permission verification.timezone - Indicates the time zone to set.0 if the time zone is set; returns a negative number otherwise.public static void sleep(long milliSecond)
milliSecond - Indicates the number of milliseconds to wait.