|
@@ -28,33 +28,50 @@ tm Time_tool::get_current_time_struct()
|
|
|
}
|
|
|
std::string Time_tool::get_current_time_seconds()
|
|
|
{
|
|
|
- auto time_tm = get_current_time_struct();
|
|
|
+ auto now = std::chrono::system_clock::now();
|
|
|
+ time_t tt = std::chrono::system_clock::to_time_t(now);
|
|
|
+ tm time_tm=*localtime(&tt);
|
|
|
char strTime[100] = "";
|
|
|
sprintf(strTime, "%d-%02d-%02d %02d:%02d:%02d", time_tm.tm_year + 1900,
|
|
|
time_tm.tm_mon + 1, time_tm.tm_mday, time_tm.tm_hour,
|
|
|
time_tm.tm_min, time_tm.tm_sec);
|
|
|
- std::string str=strTime;
|
|
|
- return str;
|
|
|
+ std::string result=strTime;
|
|
|
+ return result;
|
|
|
}
|
|
|
std::string Time_tool::get_current_time_millisecond()
|
|
|
{
|
|
|
-
|
|
|
auto now = std::chrono::system_clock::now();
|
|
|
+ time_t tt = std::chrono::system_clock::to_time_t(now);
|
|
|
+ tm time_tm=*localtime(&tt);
|
|
|
+ char strTime[100] = "";
|
|
|
+ sprintf(strTime, "%d-%02d-%02d %02d:%02d:%02d", time_tm.tm_year + 1900,
|
|
|
+ time_tm.tm_mon + 1, time_tm.tm_mday, time_tm.tm_hour,
|
|
|
+ time_tm.tm_min, time_tm.tm_sec);
|
|
|
+ std::string result=strTime;
|
|
|
//通过不同精度获取相差的毫秒数
|
|
|
uint64_t dis_millseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count()
|
|
|
- std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count() * 1000;
|
|
|
- std::string strTime=get_current_time_seconds()+" "+std::to_string((int)dis_millseconds);
|
|
|
- return strTime;
|
|
|
+ result = result+" "+std::to_string((int)dis_millseconds);
|
|
|
+ return result;
|
|
|
}
|
|
|
std::string Time_tool::get_current_time_microsecond()
|
|
|
{
|
|
|
-
|
|
|
auto now = std::chrono::system_clock::now();
|
|
|
+ time_t tt = std::chrono::system_clock::to_time_t(now);
|
|
|
+ tm time_tm=*localtime(&tt);
|
|
|
+ char strTime[100] = "";
|
|
|
+ sprintf(strTime, "%d-%02d-%02d %02d:%02d:%02d", time_tm.tm_year + 1900,
|
|
|
+ time_tm.tm_mon + 1, time_tm.tm_mday, time_tm.tm_hour,
|
|
|
+ time_tm.tm_min, time_tm.tm_sec);
|
|
|
+ std::string result=strTime;
|
|
|
+ //通过不同精度获取相差的毫秒数
|
|
|
+ uint64_t dis_millseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count()
|
|
|
+ - std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count() * 1000;
|
|
|
//通过不同精度获取相差的微秒
|
|
|
uint64_t dis_microseconds = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count()
|
|
|
- std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count() * 1000;
|
|
|
- std::string strTime=get_current_time_millisecond()+" "+std::to_string((int)dis_microseconds);
|
|
|
- return strTime;
|
|
|
+ result = result+" "+std::to_string((int)dis_millseconds)+" "+std::to_string((int)dis_microseconds);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
std::string Time_tool::get_time_string_seconds(std::chrono::system_clock::time_point time_point)
|
|
@@ -65,24 +82,41 @@ std::string Time_tool::get_time_string_seconds(std::chrono::system_clock::time_p
|
|
|
sprintf(strTime, "%d-%02d-%02d %02d:%02d:%02d", time_tm.tm_year + 1900,
|
|
|
time_tm.tm_mon + 1, time_tm.tm_mday, time_tm.tm_hour,
|
|
|
time_tm.tm_min, time_tm.tm_sec);
|
|
|
- std::string str=strTime;
|
|
|
- return str;
|
|
|
+ std::string result=strTime;
|
|
|
+ return result;
|
|
|
}
|
|
|
std::string Time_tool::get_time_string_millisecond(std::chrono::system_clock::time_point time_point)
|
|
|
{
|
|
|
+ time_t tt = std::chrono::system_clock::to_time_t(time_point);
|
|
|
+ tm time_tm=*localtime(&tt);
|
|
|
+ char strTime[100] = "";
|
|
|
+ sprintf(strTime, "%d-%02d-%02d %02d:%02d:%02d", time_tm.tm_year + 1900,
|
|
|
+ time_tm.tm_mon + 1, time_tm.tm_mday, time_tm.tm_hour,
|
|
|
+ time_tm.tm_min, time_tm.tm_sec);
|
|
|
+ std::string result=strTime;
|
|
|
//通过不同精度获取相差的毫秒数
|
|
|
uint64_t dis_millseconds = std::chrono::duration_cast<std::chrono::milliseconds>(time_point.time_since_epoch()).count()
|
|
|
- std::chrono::duration_cast<std::chrono::seconds>(time_point.time_since_epoch()).count() * 1000;
|
|
|
- std::string strTime=get_time_string_seconds(time_point)+" "+std::to_string((int)dis_millseconds);
|
|
|
- return strTime;
|
|
|
+ result = result+" "+std::to_string((int)dis_millseconds);
|
|
|
+ return result;
|
|
|
}
|
|
|
std::string Time_tool::get_time_string_microsecond(std::chrono::system_clock::time_point time_point)
|
|
|
{
|
|
|
+ time_t tt = std::chrono::system_clock::to_time_t(time_point);
|
|
|
+ tm time_tm=*localtime(&tt);
|
|
|
+ char strTime[100] = "";
|
|
|
+ sprintf(strTime, "%d-%02d-%02d %02d:%02d:%02d", time_tm.tm_year + 1900,
|
|
|
+ time_tm.tm_mon + 1, time_tm.tm_mday, time_tm.tm_hour,
|
|
|
+ time_tm.tm_min, time_tm.tm_sec);
|
|
|
+ std::string result=strTime;
|
|
|
+ //通过不同精度获取相差的毫秒数
|
|
|
+ uint64_t dis_millseconds = std::chrono::duration_cast<std::chrono::milliseconds>(time_point.time_since_epoch()).count()
|
|
|
+ - std::chrono::duration_cast<std::chrono::seconds>(time_point.time_since_epoch()).count() * 1000;
|
|
|
//通过不同精度获取相差的微秒
|
|
|
uint64_t dis_microseconds = std::chrono::duration_cast<std::chrono::microseconds>(time_point.time_since_epoch()).count()
|
|
|
- std::chrono::duration_cast<std::chrono::milliseconds>(time_point.time_since_epoch()).count() * 1000;
|
|
|
- std::string strTime=get_time_string_millisecond(time_point)+" "+std::to_string((int)dis_microseconds);
|
|
|
- return strTime;
|
|
|
+ result = result+" "+std::to_string((int)dis_millseconds)+" "+std::to_string((int)dis_microseconds);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
void Time_tool::time_start(int key)
|