• 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 
16 #ifndef RESOURCE_MANAGER_DATEUTILS_H
17 #define RESOURCE_MANAGER_DATEUTILS_H
18 
19 #include "common.h"
20 
21 namespace OHOS {
22 namespace Global {
23 namespace Resource {
24 /**
25  * Returns the current time in milliseconds.
26  *
27  * @return  the difference, measured in milliseconds, between
28  *          the current time and midnight, January 1, 1970 UTC.
29  */
CurrentTimeMillis()30 inline long CurrentTimeMillis()
31 {
32     struct timeval time;
33     gettimeofday(&time, nullptr);
34     return (time.tv_sec * KILO + time.tv_usec / KILO);
35 }
36 
37 /**
38  * Returns the current time in microseconds.
39  *
40  * @return  the difference, measured in microseconds, between
41  *          the current time and midnight, January 1, 1970 UTC.
42  */
CurrentTimeUsec()43 inline long CurrentTimeUsec()
44 {
45     struct timeval time;
46     gettimeofday(&time, nullptr);
47     return (time.tv_sec * MILLION + time.tv_usec);
48 }
49 } // namespace Resource
50 } // namespace Global
51 } // namespace OHOS
52 #endif
53