This commit is contained in:
zhangsheng 2025-05-29 10:17:07 +08:00
parent 0a085858a4
commit 8bc249ba03
2 changed files with 17 additions and 3 deletions

View File

@ -458,7 +458,19 @@ void GetTimeNet(char *timebuf, int type) {
sprintf(timebuf, "%ld", tv.tv_sec); sprintf(timebuf, "%ld", tv.tv_sec);
} }
} }
// 获取当前时区偏移(单位:秒)
int get_timezone_offset() {
time_t now = time(NULL);
struct tm gmt = *gmtime(&now);
struct tm local = *localtime(&now);
// mktime(local) 会把 local 当成本地时间转成 time_t
time_t gmt_time = mktime(&gmt);
time_t local_time = mktime(&local);
return (int)difftime(local_time, gmt_time);
}
std::string GetRTC(char *timestamp, int &millisecond) { std::string GetRTC(char *timestamp, int &millisecond) {
time_t rtc_timestamp; time_t rtc_timestamp;
struct tm tm; struct tm tm;
@ -487,13 +499,15 @@ std::string GetRTC(char *timestamp, int &millisecond) {
tm.tm_min = rtc_tm.tm_min; tm.tm_min = rtc_tm.tm_min;
tm.tm_sec = rtc_tm.tm_sec; tm.tm_sec = rtc_tm.tm_sec;
tm.tm_isdst = -1; // 婵炴垶鎸哥粔铏箾閸ヮ剚鍋ㄩ柕濞垮労濡叉儳霉閻橆喖鈧牕顪冮敓锟<E69593> tm.tm_isdst = -1; // 婵炴垶鎸哥粔铏箾閸ヮ剚鍋ㄩ柕濞垮労濡叉儳霉閻橆喖鈧牕顪冮敓锟<E69593>
// 获取本地时区偏移(秒)
rtc_timestamp = mktime(&tm); int tz_offset = get_timezone_offset();
rtc_timestamp = mktime(&tm) + tz_offset;
if (rtc_timestamp == -1) { if (rtc_timestamp == -1) {
zlog_error(zct, "fail to mktime"); zlog_error(zct, "fail to mktime");
return ""; return "";
} }
printf("Local timezone offset: %d seconds\n", tz_offset);
printf("RTC timestamp is %ld,millisecond = %d\n", rtc_timestamp, millisecond); printf("RTC timestamp is %ld,millisecond = %d\n", rtc_timestamp, millisecond);
sprintf(timestamp, "%ld", rtc_timestamp); sprintf(timestamp, "%ld", rtc_timestamp);
close(fd); close(fd);

View File

@ -299,7 +299,7 @@ std::string JsonData::JsonCmd_Cgi_10(Param_10 &param) {
sprintf(whereCon, "channelID like '%%%s%%' and %s <> ''", param.MeasurementID.c_str(), param.strStatic.c_str()); sprintf(whereCon, "channelID like '%%%s%%' and %s <> ''", param.MeasurementID.c_str(), param.strStatic.c_str());
} else { } else {
sprintf(whereCon, " channelID like '%%%s%%' and %s <> '' and timeStamp < '%s' and timeStamp > '%s' ", param.MeasurementID.c_str(), param.strStatic.c_str(), param.timeEnd.c_str(), param.timeStart.c_str()); sprintf(whereCon, " channelID like '%%%s%%' and %s <> '' and timeStamp < '%s' and timeStamp > '%s' and nodeResend = 0", param.MeasurementID.c_str(), param.strStatic.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
} }
int rows = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon); int rows = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon);