61 lines
1.4 KiB
C++
61 lines
1.4 KiB
C++
|
|
|
|
#pragma once
|
|
/**
|
|
* @file utility.h
|
|
* @brief 时间工具函数
|
|
* @author your name (you@domain.com)
|
|
* @version 0.1
|
|
* @date 2023-12-22
|
|
*
|
|
* Copyright: Baosight Co. Ltd.
|
|
* DO NOT COPY/USE WITHOUT PERMISSION
|
|
*
|
|
*/
|
|
#include <chrono>
|
|
#include <cmath>
|
|
#include <iomanip>
|
|
#include <sstream>
|
|
using namespace std::chrono;
|
|
using std::chrono::system_clock;
|
|
using TimePoint = system_clock::time_point;
|
|
using TimeDur = milliseconds;
|
|
namespace UtilityTools {
|
|
|
|
/**
|
|
* @brief 时间转当日凌晨时间
|
|
* @param time_point My Param doc
|
|
* @return TimePoint
|
|
*/
|
|
TimePoint time_point2zero(TimePoint time_point);
|
|
|
|
/**
|
|
* @brief 时间点 转 时间戳秒 (当日凌晨)
|
|
* @param time_point My Param doc
|
|
* @return int
|
|
*/
|
|
int time_point2second_zero(TimePoint time_point);
|
|
/**
|
|
* @brief 时间戳秒 转 时间点
|
|
* @param seconds My Param doc
|
|
* @return TimePoint
|
|
*/
|
|
TimePoint second_zero2time_point(int seconds);
|
|
/**
|
|
* @brief 时间差 天
|
|
* @param stime My Param doc
|
|
* @param etime My Param doc
|
|
* @return int
|
|
*/
|
|
int diff_days(TimePoint stime, TimePoint etime);
|
|
/**
|
|
* @brief str时间转chrono时间
|
|
* @param date My Param doc
|
|
* @param fmt My Param doc
|
|
* @return TimePoint
|
|
*/
|
|
TimePoint string2TimePoint(std::string date,
|
|
const std::string& fmt = "%Y-%m-%d %H:%M:%S");
|
|
|
|
} // namespace UtilityTools
|