`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
130
votes
11 answers
Get the current time in C
I want to get the current time of my system. For that I'm using the following code in C:
time_t now;
struct tm *mytime = localtime(&now);
if ( strftime(buffer, sizeof buffer, "%X", mytime) )
{
printf("time1 = \"%s\"\n", buffer);
}
The problem…

Antrromet
- 15,294
- 10
- 60
- 75
56
votes
4 answers
What primitive data type is time_t?
I do not know the data type of time_t. Is it a float double or something else? Because if I want to display it I need the tag that corresponds with it for printf. I can handle the rest from there for displaying time_t but I need to know the data…
thyrgle
34
votes
4 answers
Format specifiers for implementation-defined types like time_t
I want to make my code more platform-/implementation-independent. I don't know what a time_t will be implemented as on the platform when the code is being compiled. How do I know the type of t to determine what format specifier to use?
...
time_t t…
user198736
24
votes
5 answers
How to stop time from running backwards on Linux?
Here's a little test I've written to verify that time does indeed only run forwards in Linux.
#include
#include
bool timeGoesForwardTest2()
{
timeval tv1, tv2;
double startTime = getTimeSeconds(); // my function
…

user48956
- 14,850
- 19
- 93
- 154
23
votes
2 answers
what is the difference between difftime and '-'?
I have 2 variables of type time_t - varEnd and varStart.
Now in order to see the difference between them
Either I can do
varEnd - varStart;
or
difftime(varEnd, varStart);
and both returns number of seconds.
Please let me know, if they have any…

Naresh
- 658
- 1
- 7
- 22
22
votes
3 answers
What is the difference between clock_t, time_t and struct tm?
What is the difference between clock_t, time_t and struct tm?
struct tm looks like this:
struct tm{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
But how does clock_t and…

Cristi
- 1,195
- 6
- 17
- 24
19
votes
5 answers
Is there any way to get 64-bit time_t in 32-bit programs in Linux?
On Windows I can call:
_time32(__time32_t); // to get 32-bit time_t
_time64(__time64_t); // to get 64-bit time_t
(both in 32 and 64-bit programs)
Is there any way do this in Linux (compiling with GCC)?

chiyer
- 757
- 2
- 6
- 13
16
votes
4 answers
portable way to deal with 64/32 bit time_t
I have some code which is built both on Windows and Linux. Linux at this point is always 32-bit but Windows is 32 and 64-bit. Windows wants to have time_t be 64-bit and Linux still has it as 32-bit. I'm fine with that, except in some places…

MK.
- 33,605
- 18
- 74
- 111
15
votes
6 answers
How safe is it to assume time_t is in seconds?
I'm doing a lot of calculations with times, building time objects relative to other time objects by adding seconds. The code is supposed to run on embedded devices and servers. Most documentations say about time_t that it's some arithmetic type,…

Ant6n
- 1,887
- 1
- 20
- 26
12
votes
5 answers
64-bit Unix timestamp conversion
Is there any C++ implementation of 64-bit Unix timestamp conversions for 32-bit systems? I need to convert struct tm to 64-bit integer and vice versa, including leap years, time zones, UTC. Also need it portable, at least for GNU/Linux and Windows.

Adam Trhon
- 2,915
- 1
- 20
- 51
11
votes
4 answers
How do I convert an ISO 8601 string to time_t in C++?
Does anyone know how to go from an ISO-8601-formatted date/time string to a time_t?
I am using C++ and it needs to work on Windows and Mac.
I have written the code but I am sure there is a version that is more "standard."
I will get a date like…

reza
- 5,972
- 15
- 84
- 126
11
votes
4 answers
Addition some interval to tm structs
I have one struct tm.
And I need to add some fixed interval (given in xx years, xx months, xx days)
to the tm struct.
Is there any standard function to do this?
The compiler I use is MSVC 2005 on Windows XP.

StNickolay
- 950
- 2
- 9
- 21
10
votes
1 answer
C++ struct tm & time_t
I have an array of time here:
struct cl{
unsigned char *buffer;
time_t t = time(0);
struct tm * ct = localtime(&t);
};
and then:
cl sadi[10];
But for example I got sadi[5] at 21:58, and when I got a sadi[6] at 21:59.
Then I check…

VirusPTIT
- 115
- 1
- 8
10
votes
4 answers
How to convert a UTC date & time to a time_t in C++?
I want to convert a UTC date & time given in numbers for year, month, day, etc. to a time_t. Some systems offer functions like mkgmtime or timegm for this purpose but that is not standard and does not exist on my Solaris system.
The only solution I…

Kit Fisto
- 4,385
- 5
- 26
- 43
10
votes
7 answers
Convert date and time numbers to time_t AND specify the timezone
I have the following integers:
int y, mon, d, h, min, s;
Their values are: 2012, 06, 27, 12, 47, 53 respectively. I want to represent the date time of "2012/06/27 12:47:53 UTC" if I have selected 'UTC' somewhere else in my application, or…

bguiz
- 27,371
- 47
- 154
- 243