1,088 questions
7
votes
4
answers
346
views
How can I format a duration with std::println?
After running this program
(compiled with MSVC compiler 19.50.35723 with option /std:c++23preview)
#include <print>
#include <chrono>
#include <string>
int main() {
using ...
2
votes
2
answers
183
views
C++ hinnant date lib - not parsing string to date under Linux, works on Windows
If I do:
#include <chrono>
#include "./date/date.h"
#include "./date/tz.h"
using UtcTime = std::chrono::time_point<std::chrono::system_clock>;
UtcTime xParseRfc822(...
4
votes
3
answers
265
views
Does the returned value from `std::steady_clock::now()` denote a point in global time of the program?
Consider this example:
#include <atomic>
#include <chrono>
#include <thread>
uint64_t timestamp() {
auto now = std::chrono::steady_clock::now().time_since_epoch();
return ...
9
votes
2
answers
739
views
Using Chrono, how can I get millisecond precision?
C++, using <chrono>, I would like to get a value formatted as <seconds>.<milliseconds>. I am using system_clock and get the current seconds as:
auto secs = duration_cast<seconds&...
1
vote
1
answer
127
views
VS2022 C++: Referencing static lib project with date/date.h breaks chrono
I've come across a strange issue related to Howard Hinnant's date.h library that causes all of <chrono> to break, at least according to VS. It appears to be related to using date/date.h in a ...
3
votes
3
answers
188
views
Why chrono::timezone and format are slower than localtime_s and stringstream?
I'm generating a string representation of the current time in the local time zone for my logging system. I have an "old" version, and I wanted to see if I could improve its performance.
Old ...
6
votes
1
answer
226
views
How can I parse and format RFC-9557 date times with time zones in C++?
RFC-9557 allows tagging a time stamp with time zone information such as:
2022-07-08T00:14:07+02:00[Europe/Paris]
I would like to be able to parse this into a C++20 chrono data structure and format it ...
0
votes
1
answer
292
views
Workaround for missing std::chrono::from_stream
C++20 introduces std::chrono::from_stream() to parse date/time from a string and store it in a std::chrono::time_point. For example:
std::stringstream ss("2018-12-09T00:00:00+0130");
std::...
3
votes
1
answer
249
views
How can I format a `std::chrono::year_month_day` with libfmt?
I am using gcc-13.3 with c++23 enabled.
I have the following code which uses std::format to format a std::chrono::year_month_day to a string:
#include <chrono>
#include <format>
#include &...
7
votes
1
answer
118
views
How to stream out a C++ `zoned_time` constructed with a user-written `time_zone`
In this answer
there is a user-written time zone called OffsetZone that
can be put into a zoned_time.
#include <chrono>
class OffsetZone
{
std::chrono::minutes offset_;
public:
...
6
votes
1
answer
104
views
user-written time zones in C++ with fixed offset
I have a UTC offset that is not known until run-time, and is not necessarily an
integral number of hours. The IANA time zone
database isn't a good match for this.
What is the simplest user-written ...
30
votes
1
answer
1k
views
How can I find the Nth weekday of the month using chrono?
There are lots of Stack Overflow Q&A's solving this problem in other languages, but not so much in C++.
How do I find the Nth weekday of the month using <chrono>? For
example, what is the ...
8
votes
1
answer
147
views
How do I create a Julian calendar that will interoperate with chrono?
I would like to convert back and forth between the Julian calendar and
<chrono>'s civil calendar. What is the best way to do that?
11
votes
1
answer
758
views
Given the year, how do I compute when Easter is, using chrono
How do I write:
auto // either sys_days or year_month_day
easter(std::chrono::year y);
I'm aware of the SO question Function to return date of Easter for the given year but I would like to know how ...
22
votes
1
answer
1k
views
Find next weekday using chrono
Given a year, month and day, how do I find the next weekday on or after that
date? For example, If I have 2025-04-28, how can I find the Friday
following 2025-04-28, which is 2025-05-02?
What about ...