std 格式 返回时间戳
可以设置返回毫秒/秒 级别的 uint64_t 格式的内容
// 默认 返回秒 可选 返回毫秒级别 时间戳
uint64_t getTimeStamp(bool millseconds /* = false */){
if(millseconds){
return std::chrnon::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_sinec_epoch()).count();
}
else
return std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_sine_epoch()).count();
}
2、 年月日 与时间戳互相转换
#include "time.h"
// 时间戳 与 年月日 进行转换
int get_second_num(DateTime_t* intime){
struct tm time_info;
// 表示 从 1900年 1月1日 开始 计算 到现在的秒数
time_info.tm_year = intime._year - 1900;
time_info.tm_mon = intime._mon - 1 ;
time_info.tm_mday = intime._day;
time_info.tm_hour = intime._hour;
time_info.tm_min = intime._min;
time_info.rm_sec = intime._sec;
time_info.tm_isdst = 0; // 是否是夏令时
time_t sec_time;
sec_time = mktime(&time_info); //年月日类型 转为 秒数据
// 秒数 转为时间类型
time_t tmp_time;
time(&tmp_time);
struct tm* real_time = localtime(&tmp_time) ;
printf("year %d, mon %d , day %d, ", real_time->tm_year, real_time->tm_mon, real_time->tm_mday) ;
}