HowardHinnant / date

A date and time library based on the C++11/14/17 <chrono> header
Other
3.13k stars 675 forks source link

ISO8601 format strings #463

Open jshanab opened 5 years ago

jshanab commented 5 years ago

Having a header only include for date ontop of c++11... sounds like just what I need. but...

By far the most common format associated with ISO 8601 are strings in the form YYYY-MM-DDThh:mm:ssZ

Often used in json and xml serialized/de-serialized communications

In your examples you tend to have spaces and microseconds.

2016-05-14 18:33:24.205124 EDT

What do you suggest as the best way to use your library for these cases?

HowardHinnant commented 5 years ago
#include "date/date.h"
#include <iostream>

int
main()
{
    using namespace std;
    using namespace std::chrono;
    using namespace date;
    cout << format("%FT%TZ\n", floor<seconds>(system_clock::now()));
}

Example output:

2019-06-14T00:41:48Z
degski commented 5 years ago

This would be a useful addition to the readme.