• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { AsyncCallback, ErrorCallback } from './basic';
17
18/**
19 * System time and timezone.
20 * @since 7
21 * @syscap SystemCapability.MiscServices.Time
22 * @import systemTime from '@ohos.systemTime';
23 */
24declare namespace systemTime {
25    /**
26     * Sets the system time.
27     * @permission ohos.permission.SET_TIME
28     * @param time Target time stamp (ms)
29     * @since 7
30     */
31    function setTime(time : number, callback : AsyncCallback<void>) : void;
32    function setTime(time : number) : Promise<void>;
33
34    /**
35     * Obtains the number of milliseconds that have elapsed since the Unix epoch.
36     * @since 8
37     */
38    function getCurrentTime(isNano: boolean, callback: AsyncCallback<number>): void;
39    function getCurrentTime(callback: AsyncCallback<number>): void;
40    function getCurrentTime(isNano?: boolean): Promise<number>;
41
42    /**
43     * Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time.
44     * @since 8
45     */
46    function getRealActiveTime(isNano: boolean, callback: AsyncCallback<number>): void;
47    function getRealActiveTime(callback: AsyncCallback<number>): void;
48    function getRealActiveTime(isNano?: boolean): Promise<number>;
49
50    /**
51     * Obtains the number of milliseconds elapsed since the system was booted, including deep sleep time.
52     * @since 8
53     */
54    function getRealTime(isNano: boolean, callback: AsyncCallback<number>): void;
55    function getRealTime(callback: AsyncCallback<number>): void;
56    function getRealTime(isNano?: boolean): Promise<number>;
57
58    /**
59     * Sets the system time.
60     * @permission ohos.permission.SET_TIME
61     * @param date The target date
62     * @since 7
63     */
64    function setDate(date: Date, callback: AsyncCallback<void>): void;
65    function setDate(date: Date): Promise<void>;
66
67    /**
68     * Obtains the system date.
69     * @since 8
70     */
71    function getDate(callback: AsyncCallback<Date>): void;
72    function getDate(): Promise<Date>;
73
74    /**
75     * Sets the system time zone.
76     * @permission ohos.permission.SET_TIME_ZONE
77     * @param timezone The system time zone
78     * @since 7
79     */
80    function setTimezone(timezone: string, callback: AsyncCallback<void>): void;
81    function setTimezone(timezone: string): Promise<void>;
82
83      /**
84     * Obtains the system time zone.
85     * @since 8
86     */
87    function getTimezone(callback: AsyncCallback<string>): void;
88    function getTimezone(): Promise<string>;
89}
90
91export default systemTime;