Files
phs_v1.0.1.0/commonlibrary/c_utils/docs/zh-cn/c-utils-guide-datetime.md
2024-09-27 19:16:49 +08:00

2.0 KiB

日期与时间

概述

简介

提供一些时间的相关操作的能力增强接口。包括时间转换,获取天数和获取时区等函数。

接口说明

返回类型 名称
int64_t SecToNanosec(int64_t sec)
将秒数转换为纳秒数。
int64_t MillisecToNanosec(int64_t millise)
将毫秒数转换为纳秒数。
int64_t MicrosecToNanosec(int64_t microsec)
将微秒数转换为纳秒数。
int64_t NanosecToSec(int64_t nanosec)
将纳秒数转换为秒数。
int64_t NanosecToMillisec(int64_t nanosec)
将纳秒数转换为毫秒数。
int64_t NanosecToMicrosec(int64_t nanosec)
将纳秒数转换为微秒数。
int64_t GetSecondsSince1970ToNow()
获取从 1970 年到现在的秒数。
int64_t GetSecondsSince1970ToPointTime(struct tm inputTm)
获取从 1970 到输入时间的秒数。
int64_t GetSecondsBetween(struct tm inputTm1, struct tm inputTm2)
获取 inputTm1 和 inputTm2 之间的秒数。
int64_t GetDaysSince1970ToNow()
获取从 1970 年到现在的天数。
bool GetLocalTimeZone(int& timezone)
获取当前时区。
bool GetSystemCurrentTime(struct tm* curTime)
获取当前时间。
int64_t GetTickCount()
获取自系统启动以来的毫秒数。
int64_t GetMicroTickCount()
获取自系统启动以来的微秒数。

使用示例

  1. 测试用例编译运行方法
  • 测试用例代码参见base/test/unittest/common/utils_datetime_test.cpp

  • 使用开发者自测试框架,使用方法参见:开发自测试执行框架-测试用例执行

  • 使用以下具体命令以运行datetime_ex.h对应测试用例

run -t UT -tp utils -ts UtilsDateTimeTest