Questions tagged [c++-chrono]
<chrono> is the C++11 library for representing and manipulating time. Use [rust-chrono] for the Rust library.
c++-chrono
1,038
questions
-2
votes
1
answer
58
views
How do you update/reassign a class member Chrono::timestamp for rolling elapse times [closed]
Example code did build due to me missing something that was apart of my function implementation.
My function locally was marked as const, and I forgot to include that in the code below. Also this ...
1
vote
2
answers
84
views
std::chrono::time_point is slightly off
If I do the following:
auto time = std::chrono::system_clock::duration::zero();
std::cout << time.count() << std::endl;
time += std::chrono::years(2024 - 1970);
std::cout << time....
1
vote
2
answers
193
views
C++ how to call function at specific times of day
I need to execute a function once, at certain times of the day, like this pseudo code:
while(true)
{
now = Now();
if(now == 16:00 or now == 22:00)
{
call_function();
}
}
...
1
vote
1
answer
104
views
How to to print current time and assign it to a year_month_day variable with C++ chrono
In Visual studio 2022, C++20, I want to print the current time with year, month and day.
I tried to do it with:
cout<<today << endl
But I got this error:
Error C2679 binary "<<&...
3
votes
0
answers
62
views
signed overflow warning when extracting/inserting a timepoint from/to streams
When specifying the command line options -Wstrict-overflow=4 and -O3, extracting a timepoint (e.g. std::chrono::local_seconds) from a stream object triggers some warnings from GCC (v14.1). Inserting a ...
2
votes
1
answer
77
views
Different behaviour of high_resolution_clock on windows and linux
The high_resolution_clock::now().time_since_epoch() returns significantly different results on Windows and Linux.
On Linux it returns the duration from 1.1.1970 to now.
On Windows it returns the ...
3
votes
1
answer
65
views
std::this_thread::sleep_for with custom accelerated clock
I have many instances of std::this_thread::sleep_for(remaining_loop_time_duration).
To speed up simulation, we now were asked to use a special custom clock reference (queried using GetSimTime), which ...
0
votes
2
answers
81
views
C++ chrono library not showing all decimals
I have a code to show the time that takes to do the power of a number generated by a seed. The issue here is that I want to print the exact decimals but I keep getting 0,0006000 for example instead of ...
-2
votes
3
answers
135
views
How can I get the day of the week using std::chrono after having calculated the day/month/year?
I've calculated the day, day of month and year, and seconds, minutes, and hours using std::chrono::local_days, I just now need to get the day of the week. The code I'm using was given by Howard ...
0
votes
1
answer
54
views
Is it guaranteed that std::chrono::steady_clock always has equal tick intervals?
Are steady_clock's tick intervals stable independent of CPU throttling, load, etc? Is it reliable for measurement intervals between different events?
Will two different PC's have the same steady_clock'...
0
votes
1
answer
65
views
C++: Is it possible to get the realtime (independent of current CPU frequency and load) as unix timestamp with nanosecond precision?
Currently I calculate it as 100-nanoseconds intervals (windows FileTime) using current CPU frequency and __rdtsc() function:
typedef std::chrono::time_point<std::chrono::system_clock, std::chrono::...
0
votes
0
answers
48
views
Is there an opposite of std::format? [duplicate]
Standard format can do the following, where tm is an std::tm:
const auto time = std::chrono::system_clock::from_time_t(std::mktime(&tm));
const std::string s = std::format("{:%d %b %Y}", ...
0
votes
1
answer
58
views
How to convert std::filesystem::file_time_type to FILETIME form in c++17?
How to convert std::filesystem::file_time_type to FILETIME in C++17?
I'm expecting to get code example/snippet converting a variable of std::filesystem::file_time_type to a structure of type FILETIME ...
1
vote
1
answer
69
views
how to get time zone America/Montreal using std::chrono + MSVC 2022 + Windows 11
using MSVC 2022 with windows 11 when I try with std::chrono to get some time zone information it fails with an exception on certain time zone that I extracted from:
std::chrono::get_tzdb().zones
The ...
4
votes
2
answers
123
views
How to enumerate each hours of a day
I want to get each hours of a day, local time. For places without daylight saving time it is easy, but when there DST start or ends, current days have 23 or 25 hours!
I wrote this code to properly get ...