Skip to main content
Filter by
Sorted by
Tagged with
9 votes
2 answers
698 views

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&...
Ender's user avatar
  • 1,922
1 vote
1 answer
118 views

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 ...
angelicelyria's user avatar
3 votes
3 answers
161 views

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 ...
Carsten Kjaer's user avatar
5 votes
1 answer
209 views

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 ...
Howard Hinnant's user avatar
0 votes
1 answer
238 views

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::...
user149408's user avatar
  • 6,279
3 votes
1 answer
208 views

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 &...
Steve Lorimer's user avatar
7 votes
1 answer
118 views

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: ...
Howard Hinnant's user avatar
6 votes
1 answer
102 views

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 ...
Howard Hinnant's user avatar
30 votes
1 answer
1k views

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 ...
Howard Hinnant's user avatar
8 votes
1 answer
143 views

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?
Howard Hinnant's user avatar
11 votes
1 answer
755 views

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 ...
Howard Hinnant's user avatar
22 votes
1 answer
1k views

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 ...
Howard Hinnant's user avatar
4 votes
2 answers
124 views

The following code seems to overflow. Why? #include <chrono> #include <iostream> int main() { auto now = std::chrono::steady_clock::now(); auto low = std::chrono::steady_clock::...
CygnusX1's user avatar
  • 22.1k
2 votes
1 answer
73 views

I would like to be able to write my config file as: <?xml version="1.0" encoding="UTF-8"?> <Config> <DurationValue>20ns</DurationValue> </Config> ...
SeedlessKiwi's user avatar
2 votes
1 answer
87 views

I am writing some logic to serialize a std::chrono::time_point object to a JSON string. Here is the code I have so far: std::string get_json(const std::chrono::time_point<std::chrono::system_clock&...
user2138149's user avatar
  • 18.7k
4 votes
0 answers
141 views

I'm having some issues using chrono after 2038. My system is a 32Bit system with the following configuration Kernel: 5.15.118 GCC: 13.2.0 GLIBC: 2.38 I have compiled my program with the flags ...
Ron's user avatar
  • 41
13 votes
2 answers
533 views

I'm writing a C++ library, which works with data that has some time values in it - values that do not originate in the system the library runs on. I want to put such values in std::chrono::time_point'...
einpoklum's user avatar
  • 137k
-3 votes
3 answers
229 views

I like C++11's std::chrono facilities, which let me work with: time points clocks durations (= differences between time points) but I occasionally need to work with time intervals, i.e. not just the ...
einpoklum's user avatar
  • 137k
1 vote
1 answer
184 views

I'm trying to figure out how to use std::chrono to create and manipulate a datetime type. In particular, I need some kind of type to store a datetime type. The input and output of my program will be ...
user2138149's user avatar
  • 18.7k
6 votes
1 answer
445 views

A random unit test started failing, and I can't remember touching anything pertinent. Here's a minimal reproducible (on my machine) example: #include <chrono> #include <string> #include &...
Taylor's user avatar
  • 2,157
5 votes
3 answers
271 views

I have this simple code #include <chrono> #include <format> #include <iostream> int main() { auto time = std::chrono::system_clock::now(); std::cout << std::format(&...
Perry's user avatar
  • 1,231
1 vote
1 answer
120 views

In the following code: using seconds = std::chrono::duration<long double, std::ratio<1, 1>>; using namespace std::literals; int main() { seconds s = 10ms + 10us + 10ns; std::print(...
Fantastic Mr Fox's user avatar
1 vote
1 answer
42 views

I'm trying to use boost::property_tree to read in an infinite time duration from an XML config file for certain configurations (non-infinite for others). This code works for non-infinite durations. My ...
SeedlessKiwi's user avatar
2 votes
1 answer
220 views

The following code fails to wait for picoseconds_longlong(1'000'000'000'000). Why? #include <chrono> #include <iostream> #include <thread> using namespace std; using ...
bers's user avatar
  • 6,309
-1 votes
1 answer
130 views

I have created simple function and tried to measure execution time of it. Unfortunately because of function reordering measured time is always 0. My sample code: #include <iostream> #include <...
AdamF's user avatar
  • 2,607
0 votes
2 answers
139 views

I'm trying to write a BW generator program that sends some fixed number of reads/writes every second and then sleeps for the rest of the time. Pseudocode: for <number of iterations> ...
jkang's user avatar
  • 579
3 votes
3 answers
204 views

2038 is coming...I have to think date time in 64 bit! I'm trying to understand how to do this in C++, with chrono library, but I'm failing miserably so far. I will have to communicate a date time ...
Kite's user avatar
  • 429
1 vote
1 answer
118 views

I want to print a row of time values in the format %H%M%S and align each "cell" to specific multiple of width using std::format. My current approach is this: tps_headings += std::format(&...
glades's user avatar
  • 5,374
1 vote
1 answer
122 views

I have a std::chrono::microseconds duration that denotes the amount of microseconds that have passed since the last midnight. What's the easiest way to print it in the time format %H%M%S in c++20? ...
glades's user avatar
  • 5,374
1 vote
1 answer
79 views

I'm trying to convert std::strings such as "2024-11-19 09:30:00.037000" **that I know to always be in Eastern time) to std::chrono objects and vice versa, but I can't get anything to work ...
Taylor's user avatar
  • 2,157
2 votes
1 answer
264 views

I want to convert a UTC year, month, day to a std::chrono::time_point (and also display it). #include <chrono> using namespace std::chrono; void DisplayDate(int y, int m, int d) {//e.g. 2024, ...
Dominik Weber's user avatar
0 votes
1 answer
216 views

Using C++20, given (year, month, day) as integers, I want to find the next day, also as (year, month, day). There is a data type in std::chrono, year_month_day, that seems appropriate. But I cannot ...
Woody20's user avatar
  • 867
3 votes
1 answer
332 views

For reference, I'm in GMT+1. I set my system clock to 0:13 am today (nov 15th 2024). Trying the canonical code from cppreference: const std::chrono::time_point<std::chrono::system_clock> now = ...
Basti's user avatar
  • 2,498
0 votes
1 answer
62 views

How to update date in a datepicker element. I have a int64_t attribute m_myDate that contains the date. TimeSpan is a specialization of std::chrono::duration. DateTime a specialization of std::chrono:...
Tirsvad's user avatar
  • 186
2 votes
2 answers
208 views

What is the standard/typical method when implicitly converting between time units using std::chrono? E.g. from ms to ns // #1 constexpr uint64_t foo_ns = std::chrono::milliseconds(500) / std::chrono::...
Matt Stokes's user avatar
  • 5,068
1 vote
1 answer
85 views

I'm attempting to allow setting the units that a std::chrono::duration is reported in by modifying an xml config file parsed by boost::property_tree. My current, non-compiling solution attempts to do ...
SeedlessKiwi's user avatar
1 vote
1 answer
170 views

#include <iostream> #include <chrono> int main() { constexpr std::chrono::duration<float> kLastWarningMsgDuration{ 10 }; // default time point (zero) std::chrono::...
Miro Kropacek's user avatar
2 votes
1 answer
114 views

This program should, I think, produce different results if in a different locale: #include <chrono> #include <iostream> #include <locale> using namespace std; int main(int, char *...
John Graham's user avatar
3 votes
2 answers
217 views

This works: year_month_day day() { return year_month_day(floor<days>( zoned_time{ zone, system_clock::now() }.get_local_time())); } ...
John Graham's user avatar
2 votes
1 answer
84 views

So I'm trying to capture a stream and write it to 30 seconds chunks. I don't know what the cameras fps will be so need to factor in that I want to only capture 15 fps. my problem is that the following ...
danielRICADO's user avatar
1 vote
1 answer
119 views

How to get value of std::formatter<std::chrono::zoned_time> to use repeatedly? I need to be able to format time with the same format string repeatedly. I can't seem to figure out how to keep the ...
wilx's user avatar
  • 18.3k
2 votes
1 answer
137 views

#include "date/tz.h" #include "date/date.h" #include <iostream> #include <string> int main() { using namespace date; using namespace std; using namespace chrono; auto ...
tech1978's user avatar
  • 123
1 vote
1 answer
140 views

I have a duration as string e.g. "13:00:00" and a time_point parsed to a utc_time from an UTC time string using std::chrono::parse function. Now given this duration and a timezone e.g. "...
Roger World's user avatar
4 votes
1 answer
201 views

I'm trying to use the <chrono> library to parse a POSIX date and time string, no matter what the global locale is, based on this code: #include <iostream> #include <locale> #include &...
LightGolgot's user avatar
6 votes
2 answers
701 views

I've got an algorithm I've used for years to emulate a real-time clock in a non-real-time environment. It's always worked exceptionally well until used on Ubuntu 24.04 in WSL2 in Windows 11. The logic ...
Todd Blumer's user avatar
3 votes
1 answer
200 views

I am trying to use alias for std::chrono and std::chrono::duration_cast<std::chrono::seconds> which are throwing compilation errors. I included <chrono> header file. Below is the code: #...
kadina's user avatar
  • 5,396
1 vote
2 answers
142 views

Summary: Given a numeric type T, is there a concise way to declare a variable as either std::uniform_int_distribution<T> or std::uniform_real_distribution<T> depending upon whether T is ...
Adrian McCarthy's user avatar
3 votes
3 answers
213 views

Methods to time a block of code in C++ have been well documented, e.g., here and here. In the answers to the questions linked, we usually need to write some lines of code at the start and end of the ...
josh_eime's user avatar
  • 176
2 votes
1 answer
137 views

I want to set the variable of type gps_clock from a string, e.g. "2024-08-09T22:20:50". My linux distribution uses gcc13. In this version the methods of std::chrono::from_stream and std::...
Johannes's user avatar
4 votes
1 answer
187 views

I need to parse a timestamp with timezone into a c++ timepoint. My environment is linux and gcc 14.1 and -std=c++23. My definitions are: namespace MyTime { using clock_t = std::chrono::...
schorsch_76's user avatar

1
2 3 4 5
22