`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
4
votes
4 answers
getting utc timestamp using strftime()
I am trying to encode current UTC time into string using the strftime function:
time_t now;
struct tm nowLocal;
struct tm nowUtc;
now = time(NULL);
localtime_r(&now, &nowLocal);
gmtime_r(&now, &nowUtc);
So far so good: nowLocal contains current…

Petr
- 108
- 1
- 6
3
votes
0 answers
Converting http date header string to time_t
I want to convert the http header field "Date", which is returned to me in the format
"Wed, 07 Mar 2012 09:58:26 GMT", into a time_t value.
I'm not sure if there's a standard format for this field in the http headers.
I saw this: parsing of…

Itzuke
- 43
- 4
3
votes
2 answers
Converting seconds since epoch to time_t
I have a string representing seconds since epoch, and I need to convert it to a human readable string. I've seen a few posts online that suggest simply casting an integer to time_t as so:
time_t time = (time_t)(atoi(secs_since_epoch_str));
But, if…

HardcoreHenry
- 5,909
- 2
- 19
- 44
3
votes
2 answers
Can I avoid going through time_t to print a time_point?
Here's an example adapted from cppreference.com :
#include
#include
#include
#include
int main() {
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
std::time_t now_c =…

einpoklum
- 118,144
- 57
- 340
- 684
3
votes
3 answers
Get time_t / timeval corresponding to ( local_timezone ) midnight on a given date
Given a time_t or struct timeval, how do I get the timeval or time_t of midnight EST/EDT ( local timezone ) on that day ?
As in assuming local timezone is EST/EDT, given a time_t corresponding to say 2010-11-30 08:00:00 EST/EDT, the expected answer…

Humble Debugger
- 4,439
- 11
- 39
- 56
3
votes
3 answers
C++ date comparison does not always evaluate to the same logical value
I am making a project that has to keep track of dates associated with books. I store the dates as strings. I need to print out all books that were published after a given date.
Below is a loop similar to what I do in my code which replicates a…

K. Shores
- 875
- 1
- 18
- 46
3
votes
1 answer
How do I convert a Unix timestamp string to time_t in C++11?
Short question, aka "TD;DR".
I have a, say, "1464478647000" string, that I guess is a UNIX timestamp. But surely it is a string containing a number that represents time, but not in a human readable format. How do I convert it to a time_t type so I…

acidrums4
- 217
- 3
- 12
3
votes
4 answers
Convert `time_t` to decimal year in C++
How can I convert a time_t structure to years as decimal?
For example, for a date 2015-07-18 00:00:00 I would like to get 2015.625.

SSV
- 33
- 1
- 5
3
votes
1 answer
Time-server time type issue
so I'm writing a little time server-client application in C on linux that's supposed to send the current unix time stamp to the client.
It works all fine and all, but I've been told that time_t might not always be the same size and byte order. How…

rfreytag
- 1,203
- 11
- 18
3
votes
2 answers
Testing for leap seconds for a given time_t in Linux
Is there a simple way of determining how many (if any) leap seconds are applied for a given implementation of:
time_t unix_seconds = mktime(&my_tm);
For example, is there a field that is populated in my_tm?
Otherwise, I suppose my option is test…

Damien
- 785
- 3
- 8
- 18
3
votes
5 answers
Printing time in seconds
I am writing a program and attempting to time the number of seconds that passes when a given block of code runs. Afterwards I would like to print the total time it took to run the block of code in seconds. What I have written is:
time_t start =…

raphnguyen
- 3,565
- 18
- 56
- 74
3
votes
2 answers
How to convert the negative timestamp to a string. C++
I have the negative timestamp (that is date older 1970, e.g. 15.04.1896). How to convert the given timestamp to the correct date string.
As I'm trying to do it
#include
#include
#include
int _tmain(int argc, _TCHAR*…

Artem Zubkov
- 559
- 1
- 14
- 29
3
votes
4 answers
Checking if time_t is between other time_t with some margin of error
I have two time_t variables: timeA and timeB.
What I want to do is check if timeA is the same as timeB. However, I know that in some cases they won't be exactly the same and there may be a 1 or 2 seconds difference between the two of them, so what I…

Alex
- 315
- 1
- 6
- 19
2
votes
1 answer
Incorrect result after adding days to date
Using below function, which simply adds days to date (yyyymmdd), works fine throughout years.
int dateplusdays(int datein, int days) {
int year, month, day;
int dateout;
struct tm date;
time_t secs;
year = (int)floor(datein /…

geohei
- 696
- 4
- 15
2
votes
1 answer
Comparing a time_t to a struct timespec (in C)
I have multiple struct timespec values and a time_t value. I want to see which struct timespec value is the closest to the time_t value. Should I just compare the seconds and ignore the nanoseconds? Or should I convert both to total nanoseconds…

jetset
- 388
- 4
- 14