You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the DOOCS clientlib we have functions for formatting local time:
/**
* Convert a timestamp into local time and format it into a std::string using strftime()
* format specifiers.
*
* Due to the limitations of strftime(), this function does not support sub-second
* output precision.
*
* \param ts The timestamp to be formatted.
* \param fmt A format string following the specifications of strftime(), see
* https://en.cppreference.com/w/cpp/chrono/c/strftime . If fmt is a null
* pointer, an empty string is returned. The default format generates an
ISO 8601 compliant date-time string.
* \returns a string with the formatted output or an empty string if an error occurred.
*/
std::string format_localtime (Timestamp ts, const char *fmt = "%Y-%m-%dT%H:%M:%S");
std::string format_localtime (std::time_t t, const char *fmt = "%Y-%m-%dT%H:%M:%S");
Such functions are useful also for other projects (both for UTC and local times). I'd say we could use them in GUL14.
Hmm, I'd like to see Howards date as a 'backport-ish' thing, like optional.
It's single header. I usually just grab that one file and throw it into my source-tree, but would rather like to have it in GUL instead.
And it has subsecond resolution. Usually use it like this
auto tp = system_clock::now();
std::cout << tp << '\n';
2015-04-19 18:24:42.770911
Of course you can generate the unreadable ISO 8601 or, as I prefer RFCs over ISO, RFC 3389 strings.
So, if you look again at the RFC document. RFC 3339 use/follow the ISO 8601 profile for the Internet DateTime. Clearly stated in chapter 5.6
So actually, there are no big differences between Date ISO 8601. The only small thing that makes these 2 different is the “T” syntax between date and time. ISO 8601 uses the “T” character to separate the date and time. In RFC 3339, you can replace the “T” character with only using space.
For example:
# This is acceptable in ISO 8601 and RFC 3339 (with T)
2019-10-12T07:20:50.52Z
# This is only accepted in RFC 3339 (without T)
2019-10-12 07:20:50.52Z
Activity
Finii commentedon Jul 18, 2022
Hmm, I'd like to see Howards date as a 'backport-ish' thing, like
optional.It's single header. I usually just grab that one file and throw it into my source-tree, but would rather like to have it in GUL instead.
Newer description with other date-time stuff here: https://github.com/HowardHinnant/date
And it has subsecond resolution. Usually use it like this
Of course you can generate the unreadable ISO 8601 or, as I prefer RFCs over ISO, RFC 3389 strings.
Source here for an interested reader
Of course any formatting is possible, as with the
Cstyle format string, bystd::formatterI mean, no that is C++20, butdate::formatIf we need timezones, that is another header file. I never used this.