Commit c7a4adb9 by guanghui.cui

时间戳转换

parent 4632a17e
......@@ -93,5 +93,7 @@
//推送类型
#define ODS_PUSH_TYPE_HEARTBEAT 3 //心跳
#define ODS_PUSH_TYPE_STOCKWARN 1006 //库存预警
#define ODS_PUSH_TYPE_COMMON 1017 //通用预警
#define ODS_PUSH_TYPE_COMMON_BACK 1018 //通用预警返回
#endif
\ No newline at end of file
#include "JsonModule.h"
#include "../utility/utility.h"
#include "../3rdParty/rapidjson/rapidjson.h"
#include "../3rdParty/rapidjson/document.h"
#include "../3rdParty/rapidjson/reader.h"
......@@ -1425,7 +1426,8 @@ void JsonModule::_getStockWarnObj(IN const char* json,OUT stockWarnObj &warn_obj
}
rapidjson::Value& alertTime = document["alertTime"];
detail.alertTime = alertTime.GetString();
int64_t iDatetime = alertTime.GetInt64();
detail.alertTime = getdatetime(iDatetime);
warn_obj.vecProducts.push_back(detail);
}
......
......@@ -195,7 +195,7 @@ int main()
/// 注册回调函数
el::Helpers::installPreRollOutCallback(logRolloutHandler);
LOG(INFO)<<"---------software start---------";
LOG(INFO)<<"---------software start---------.";
//sqlite初始化
if(!sqlite.initSQLite()){
......
......@@ -6,6 +6,7 @@
#include <iconv.h>
#include <string.h>
#include <sys/time.h>
#include <chrono>
#ifdef WIN32
#include <Windows.h>
......@@ -106,4 +107,18 @@ int64_t timestamp_seconds()
struct timeval tv;
gettimeofday(&tv,NULL);
return tv.tv_sec;
}
std::string getdatetime(int64_t timestamp)
{
std::string strDate;
int64_t milli = timestamp+ (int64_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);
char datetime[64];
sprintf(datetime,"%4d%02d%02d%02d%02d%02d",now->tm_year+1900,now->tm_mon+1,now->tm_mday,now->tm_hour,now->tm_min,now->tm_sec);
strDate=datetime;
return strDate;
}
\ No newline at end of file
......@@ -19,4 +19,7 @@ int64_t timestamp_seconds();
//获取时间戳(毫秒)
int64_t timestamps_milliseconds();
//根据时间戳获取时间
std::string getdatetime(int64_t timestamp);
#endif
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment