首页
学习
活动
专区
圈层
工具
发布
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    使用strptime函数时遇到的一个坑

    做新专辑排序的需求时,需要对专辑的时间进行排序,由于目前该字段是字符串类型的日期,在排序函数中要转成标准的UNIX时间戳来进行对比,大概代码如下: struct tm tm1; strptime(string...18").c_str(), "%Y-%m-%d", &tm1); time_t t1 = mktime(&tm1); std::cout << t1 << endl; struct tm tm2; strptime...这里有提到说如果是从strptime()取到的值,tm_isdst的值是不确定的,必须手动指定。因此想到,是否对于未做初始化的struct tm,strptime()函数并不会去给每个值赋值。...查看strptime It is unspecified whether multiple calls to strptime() using the same tm structure will update...因此,解决方法就是在使用strptime()之前,对结构体进行零初始化(zero-initialize) struct tm tm1 = {0}; ... struct tm tm2 = {0};

    2.5K80
    领券