0

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...

Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
JWood
  • 2,804
  • 2
  • 39
  • 64

2 Answers2

1

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.

Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
0

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

obelix
  • 986
  • 8
  • 14