大家好,欢迎来到IT知识分享网。
//vov
#ifndef VTIME_HPP
#define VTIME_HPP
#include <cstdio>
#include <ctime>
#include <string>
#include <chrono>
#include <sys/time.h>
static const std::string vTimeStamp() {
time_t tt=time(NULL);
struct tm *stm=localtime(&tt);
char tmp[50];
sprintf(tmp, "%04d%02d%02d%02d%02d%02d",
1900 + stm->tm_year,
1 + stm->tm_mon,
stm->tm_mday,
stm->tm_hour,
stm->tm_min,
stm->tm_sec);
std::string res(tmp);
return res;
}
static const std::string vTimeStampMilli()
std::string vTimeStampMilli()
{
struct timeval tv;
gettimeofday(&tv, NULL);
struct tm* ptr_tm = std::localtime(&tv.tv_sec);
std::stringstream ss;
ss << std::setfill('0');
ss << ptr_tm->tm_year + 1900 << "-";
ss << std::setw(2) << ptr_tm->tm_mon + 1 << "-";
ss << std::setw(2) << ptr_tm->tm_mday << " ";
ss << std::setw(2) << ptr_tm->tm_hour << ":";
ss << std::setw(2) << ptr_tm->tm_min << ":";
ss << std::setw(2) << ptr_tm->tm_sec << ".";
ss << std::setw(3) << tv.tv_usec / 1000;
return ss.str();
}
static const std::chrono::steady_clock::time_point vTimePoint() {
return std::chrono::steady_clock::now();
}
static double vTimePointDiff(std::chrono::steady_clock::time_point t1,
std::chrono::steady_clock::time_point t2) {
return std::chrono::duration_cast<std::chrono::duration<double>>(t2-t1).count()*1000;
}
#endif
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/33083.html