开发者

Parsing RFC3339 dates in C++

Are there any functions available to parse an RFC3339 date in C++ (even if they are Win32 specific)? I was previously using Qt and the QDateTime::fromString() function to parse the date but I am now using plain old Win32 C++ (No MFC) and I'm struggling to find a way to do it. If there is no standard in way I can write my开发者_如何学运维 own but just in case I missed something...


For parsing and comparing RFC3339 formated dates, you can use Howard Hinnant's date library.
It can be used as followed:

#include "date/date.h"
#include <iostream>
#include <sstream>

int main()
{
    using namespace date;
    std::istringstream infile{"2005-08-15T15:52:01+04:00"};
    sys_seconds tp;  // This is a system_clock time_point with seconds precision
    infile >> parse("%FT%T%Ez", tp);
    std::cout << tp.time_since_epoch() << " is " << tp << '\n';
}

A slightly modified versions of "date.h" and "tz.h" were voted into the C++20 working draft.


I'm not aware of any standard api - atleast on windows. I think you'll have to write your own ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜