diff --git a/common/common_func.cpp b/common/common_func.cpp index 4fea216..9f5daa9 100644 --- a/common/common_func.cpp +++ b/common/common_func.cpp @@ -458,7 +458,19 @@ void GetTimeNet(char *timebuf, int type) { 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) { time_t rtc_timestamp; struct tm tm; @@ -487,13 +499,15 @@ std::string GetRTC(char *timestamp, int &millisecond) { tm.tm_min = rtc_tm.tm_min; tm.tm_sec = rtc_tm.tm_sec; tm.tm_isdst = -1; // 婵炴垶鎸哥粔铏箾閸ヮ剚鍋ㄩ柕濞垮労濡叉儳霉閻橆喖鈧牕顪冮敓锟� - - rtc_timestamp = mktime(&tm); + // 获取本地时区偏移(秒) + int tz_offset = get_timezone_offset(); + rtc_timestamp = mktime(&tm) + tz_offset; if (rtc_timestamp == -1) { zlog_error(zct, "fail to mktime"); return ""; } + printf("Local timezone offset: %d seconds\n", tz_offset); printf("RTC timestamp is %ld,millisecond = %d\n", rtc_timestamp, millisecond); sprintf(timestamp, "%ld", rtc_timestamp); close(fd); diff --git a/jsonparse/web_cmd_parse.cpp b/jsonparse/web_cmd_parse.cpp index f03dccd..988ea05 100644 --- a/jsonparse/web_cmd_parse.cpp +++ b/jsonparse/web_cmd_parse.cpp @@ -299,7 +299,7 @@ std::string JsonData::JsonCmd_Cgi_10(Param_10 ¶m) { sprintf(whereCon, "channelID like '%%%s%%' and %s <> ''", param.MeasurementID.c_str(), param.strStatic.c_str()); } 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);