[C++] strptime : 네이버 블로그 您所在的位置:网站首页 仓库分拣员 [C++] strptime : 네이버 블로그

[C++] strptime : 네이버 블로그

#[C++] strptime : 네이버 블로그| 来源: 网络整理| 查看: 265

출처 : https://code.i-harness.com/ko/q/4e939

#include #include #include extern "C" char* strptime(const char* s, const char* f, struct tm* tm) { // Isn't the C++ standard lib nice? std::get_time is defined such that its // format parameters are the exact same as strptime. Of course, we have to // create a string stream first, and imbue it with the current C locale, and // we also have to make sure we return the right things if it fails, or // if it succeeds, but this is still far simpler an implementation than any // of the versions in any of the C standard libraries. std::istringstream input(s); input.imbue(std::locale(setlocale(LC_ALL, nullptr))); input >> std::get_time(tm, f); if (input.fail()) { return nullptr; } return (char*)(s + input.tellg()); }time_t build_time() { static const char *built = __DATE__ " " __TIME__; struct tm t; const char *ret = strptime(built, "%b %d %Y %H:%M:%S", &t); if (ret == nullptr) { return 0; } return mktime(&t); }



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有