• 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 UTILITY_TIME_UTIL_H
17 #define UTILITY_TIME_UTIL_H
18 
19 #include <cstdint>
20 #include <ctime>
21 #include <string>
22 
23 namespace OHOS {
24 namespace HiviewDFX {
25 namespace TimeUtil {
26 constexpr int64_t SEC_TO_NANOSEC = 1000000000;
27 constexpr int64_t SEC_TO_MICROSEC = 1000000;
28 constexpr int64_t SEC_TO_MILLISEC = 1000;
29 constexpr int64_t MILLISEC_TO_NANOSEC = 1000000;
30 constexpr int64_t MICROSEC_TO_NANOSEC = 1000;
31 constexpr int SECONDS_PER_MINUTE = 60; // 60 seconds
32 constexpr int SECONDS_PER_HOUR = 3600; // 60 * 60
33 constexpr int SECONDS_PER_DAY = 86400; // 60 * 60 * 24
34 constexpr int MAX_TIME_BUFF = 64; // 64 : for example 2021-05-27-01-01-01
35 uint64_t GetNanoTime();
36 uint64_t GetTimeOfDay();
37 uint64_t GenerateTimestamp();
38 uint64_t GetMilliseconds();
39 time_t StrToTimeStamp(const std::string &tmStr, const std::string& format);
40 void Sleep(unsigned int seconds);
41 int GetMillSecOfSec();
42 std::string TimestampFormatToDate(time_t timeStamp, const std::string& format);
43 std::string GetTimeZone();
44 int64_t Get0ClockStampMs();
45 } // namespace TimeUtil
46 } // namespace HiviewDFX
47 } // namespace OHOS
48 #endif // UTILITY_TIME_UTIL_H