|
- #pragma once
- #include <ctime>
- #include <iostream>
- #include <fstream>
- #include <direct.h>
- using namespace std;
- #ifndef __EASYLOG_PIPI_0813
- #define __EASYLOG_PIPI_0813
- class EasyLog
- {
- public:
- static void Write(std::string log) {
- try
- {
- std::ofstream ofs;
- time_t t = time(0);
- char tmp[64];
- strftime(tmp, sizeof(tmp), "[%Y-%m-%d %X]", localtime(&t));
- ofs.open("D:\PipeLog.log", std::ofstream::app);
-
- ofs << tmp << " - ";
- ofs.write(log.c_str(), log.size());
- ofs << std::endl;
- ofs.close();
- }
- catch(...)
- {
- }
- }
- };
- #endif
复制代码- std::time_t getTimeStamp()
- {
- std::chrono::time_point<std::chrono::system_clock,std::chrono::milliseconds> tp = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now());
- auto tmp=std::chrono::duration_cast<std::chrono::milliseconds>(tp.time_since_epoch());
- std::time_t timestamp = tmp.count();
- //std::time_t timestamp = std::chrono::system_clock::to_time_t(tp);
- return timestamp;
- }
- std::tm* gettm(std::time_t timestamp)
- {
- std::time_t milli = timestamp/*+ (std::time_t)8*60*60*1000*/;//此处转化为东八区北京时间,如果是其它时区需要按需求修改
- auto mTime = std::chrono::milliseconds(milli);
- auto tp=std::chrono::time_point<std::chrono::system_clock,std::chrono::milliseconds>(mTime);
- auto tt = std::chrono::system_clock::to_time_t(tp);
- std::tm* now = std::gmtime(&tt);
复制代码
|
|