`time_t` is a Standard-C data type to hold the seconds since UNIX epoch, that since the 1.1.1970.
Questions tagged [time-t]
171 questions
2
votes
1 answer
Comparing file stat times
I need to watch for the modification of a file on a Unix based system, and I do not have access to Boost. I am wondering if the following logic is sound. I figure it's probably inefficient, and I know I am wasting a ton of cycles by not sleeping at…

cooper
- 315
- 1
- 16
2
votes
2 answers
How to convert boost local_date_time to time_t
I have:
time_t dataFromTodayByAddingYearsMonthsDays(int years, int months, int days)
{
using namespace boost::local_time;
local_date_time local = local_sec_clock::local_time(time_zone_ptr());
local +=…

meaning-matters
- 21,929
- 10
- 82
- 142
2
votes
2 answers
Convert milliseconds to time_t
I have the number of milliseconds starting from 2004 to a specific date. I want to convert this to time_t to display it with ctime()?
Perhaps there is another method to visualize the date by this milliseconds timestamp, does anyone have one?

illvoid
- 43
- 1
- 7
2
votes
2 answers
C - error storing time_t variable in a struct [time.h]
I'm working on building a process scheduler that follows the FIFO algorithm. I've written all the code and it is working, except for the part of the report. Here an example of how the report is coming out:
FIFO PROCESS SCHEDULER
Simulation # Report:…

linuxunil
- 313
- 2
- 14
2
votes
1 answer
Have any method make HP-UX 11.31(IA64) support 64-bit time_t
I'm be surprised to learn type long and time_t are 4-byte sized in this HP-UX 11.31(IA64). May I ask why?
My environment:
$ uname -a
HP-UX bdev1 B.11.31 U ia64 0999202893 unlimited-user license
$ cat /usr/include/sys/_time_t.h
......
# ifndef…

van
- 213
- 1
- 3
- 10
1
vote
4 answers
Representing the difference between time_t
Why is the difference between two time_ts returned by the difftime( time_t t1, time_t t2) method as a double? I don't see where the precision requirement comes from.

Konrad
- 39,751
- 32
- 78
- 114
1
vote
2 answers
How to tell if it's before a configured time in C++?
I'm trying to find the best way to see if the current time is before a specified time. Say I want to see if it's before 14:32. What's the best way to do this in C++? Ideally I'd be able to build some time object that represents 14:32, then compare…

Joshua Segal
- 99
- 6
1
vote
2 answers
How to find Time Duration between two dates with Hours minutes and seconds in C++ 11?
I need to find the time difference between two given dates.
I have tried the following code but not able to convert it into hours mins secs
const char *time_details = "06/10/2021 16:35:12";
struct tm tm;
strptime(time_details, "%m/%d/%Y…

Aravind
- 1,521
- 2
- 12
- 23
1
vote
1 answer
clock() function doesn't measure qsort() time
I'm trying to write a program that takes some song data (~1000 lines) from a CSV file and puts it into a struct array. Each line from that CSV file contains: title of the song, artist and release year. String, string and int.
No problems when taking…

Mateaș Mario
- 113
- 1
- 7
1
vote
2 answers
localtime() crashes when pass value >0x7FFFFFFF
According to my understanding time_t rawtime = 0xffFFffFF is GMT: Sunday, February 7, 2106 6:28:15 AM
But the program below brings Thu 1970-01-01 02:59:59 MSK in some compilers and just crashes in others.
int main()
{
time_t rawtime =…

vico
- 17,051
- 45
- 159
- 315
1
vote
1 answer
C++ Read time_t in to different timezone then extract year/month....nanoseconds
I'm extracting the year/month/day/hours/min/sec/nanoseconds from a source containing nanoseconds since Epoch, using the answer to the below question:
Extract year/month/day etc. from std::chrono::time_point in C++
However, my input is a different…

user997112
- 29,025
- 43
- 182
- 361
1
vote
1 answer
How to initialize std::vector with n elements in constructor initializer list
I am trying to initialize vector in constructor initializer list like so:
Foo::Foo()
: vec{42}
{
// ...
}
The vector is declared as:
std::vector vec;
Problem is that std::time_t is numeric type also, so instead of creating…

Irma
- 47
- 1
- 8
1
vote
2 answers
How to use mktime64(), time64() and localtime64() function with 32-bit time library?
How to use the mktime64() in Linux with 32-bit time library to avoid the year 2038 issue?
We have tried using the macro _Time64 but failed as compiler still throws undefined mktime64() error:
typedef long long _Time64_t;
_Time64_t _Time64(_Time64_t…

Gaurav_is_lucky
- 11
- 4
1
vote
1 answer
Teensy's #include got overridden by Arduino
In Arduino C+, I wanted to avoid the year 2038 overflow problem when using 32-bit, signed time_t type, so that I'd like to specifically use the Time.h from Teensy (Or TimeLib.h for that matter; I am writing code for Teensy 3.5 on Arduino 1.8.7).
But…

Dave
- 133
- 8
1
vote
2 answers
Difference in seconds between two dates in C
I want to calculate the difference in seconds between two dates but the result is 0.
Here is the code:
time_t=time(NULL);
struct tm * timeNow=localtime();
time_t start=mktime(&*timeNow);
time_t end=mktime(&*recordFind->timeInserted);
double…

joesid
- 671
- 1
- 10
- 21