Browse Source

初始化struct tm变量

zzj 6 years ago
parent
commit
d21313a51f
1 changed files with 2 additions and 2 deletions
  1. 2 2
      tool_time.h

+ 2 - 2
tool_time.h

@@ -46,7 +46,7 @@ public:
     {
         char _time[25] = {0};
         time_t tt = std::chrono::system_clock::to_time_t(time);
-        struct tm local_time;
+        struct tm local_time={0};
         localtime_r(&tt, &local_time);
         strftime(_time, 22, "%Y-%m-%d %H:%M:%S", &local_time);
 
@@ -64,7 +64,7 @@ public:
     static time_t to_time(const std::string&str)
     {
         time_t t_;
-        tm tm_;
+        tm tm_={0};
         strptime(str.c_str(), "%Y-%m-%d %H:%M:%S", &tm_); //将字符串转换为tm时间
         t_ = mktime(&tm_); //将tm时间转换为秒时间