`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
2 answers
printf epochtime shows wrong values
I am experimenting with time_t variables, and this is the code in question:
#include
#include
#include
struct tm epochtime;
time_t epochdate;
int main()
{
epochtime.tm_mday = 19;
epochtime.tm_mon = 10;
…

BeNicePlz
- 43
- 6
2
votes
1 answer
Formatting time c++ dd/mm/yyyy hh:ss
I am trying to get the date and time (NOW) here is what I have got so far:
16/1/2020 13:24
How can I get dd/mm and also how to set time non UTC? The time should be 12:24pm
time_t rawtime
struct tm ltm;
time(&rawtime)
localtime_s(<m,…

Mr Tea
- 117
- 9
2
votes
2 answers
Adding and subtracting time with tm
So say I set a time in tm to be 23:00:00
ptm->tm_hour = 23; ptm->tm_min = 0; ptm->tm_sec = 0;
And I want to allow a user to subtract time from this
ptm->tm_hour -= hourinput; ptm->tm_min -= minuteinput; ptm->tm_sec -= secondinput;
If the user…

Zevvysan
- 283
- 2
- 13
2
votes
3 answers
Getting difference between two date to timestring in seconds using c++
I need to find the difference between two date to time periods in seconds. Here is what I did: Assigned the date and time variables using sscanf. Assigned the variables to struct tm object (timeInfo).
Example of time string: Thu, 29 Mar 2018…

KESHAV K
- 63
- 10
2
votes
3 answers
how to convert struct tm to time_t in c++
the given function is a part of a class which is used to handle date and time.the file i parse needs to convert the given string data to time_t yet mktime does not work. why?
struct tm DateTimeUtils::makeTime(string arrTime)//accepts in…

tanvi rustagi
- 21
- 1
- 2
2
votes
2 answers
C++ custom time date struct to utc epoch
I use a library that uses the following struct to define a start timestamp as follows.
struct SYSTEMTIME {
/** year */
WORD year;
/** month */
WORD month;
/** day of week */
WORD dayOfWeek;
/** day */
WORD…

Dennis Delin
- 25
- 8
2
votes
3 answers
Copying struct tm
The glibc version of struct tm has additional fields
long tm_gmtoff; /* Seconds east of UTC */
const char *tm_zone; /* Timezone abbreviation */
(Ref: http://linux.die.net/man/3/ctime )
My question is: If I have a data called struct…

Dr. Debasish Jana
- 6,980
- 4
- 30
- 69
2
votes
2 answers
How to represent uninitialized value for time_t type in c
I have a time_t type variable (from ) that stores the time of a failure, and would like to initialize it to a "null" value that will be the final value if no error occurs. Is there a standard way to set a time_t variable to some kind of…

robisrob
- 940
- 12
- 23
2
votes
2 answers
Check if time_t is zero
I have written a timer eventloop with epoll and the timerfd linux API. The magpage of timerfd_gettime states the following:
The it_value field returns the amount of time until the timer will
next expire. If both fields of this structure are zero,…

Daan Pape
- 1,100
- 1
- 13
- 25
2
votes
1 answer
convert string to time_t and then convert time_t back to string
I want to save a date time string to time_t and then convert it back to exactly original string.
But the code below will output "2016-04-25_10:10:05"
And the hour in the output will be incorrect by changing the date_str.
If you change the code to…

Christophe
- 195
- 2
- 9
2
votes
2 answers
Best way to convert Unix time_t to/from abitrary timezones?
My code receives a time_t from an external source. However, that time_t isn't acutally based on UTC Epoch time, along with it I get a timezone string (eg, EDT, PST, etc), and its based on this offset'ed epoch. I need to convert this to a true UTC…

bdk
- 4,769
- 29
- 33
2
votes
1 answer
Convert time_t to string and string to time_t gives wrong year and an hour
I'm trying and trying to write functions to help myself easily convert string to time_t and time_t to string. However, it always gives me wrong a year and a wrong hour. What's wrong?
I need it to be OS independent!
For instance, for date…

mazix
- 2,540
- 8
- 39
- 56
2
votes
3 answers
C/C++ time_t in microseconds
This program returns the time in seconds. I need to return it in microseconds.
time_t timeStart = time(0);
usleep(2.5e6);
time_t timeEnd = time(0);
float R = (timeEnd - timeStart);
std::cout << R << std::endl;

Strife
- 39
- 1
- 1
- 3
2
votes
3 answers
Two separate tm structs mirroring each other
Here is my current situation:
I have two tm structs, both set to the current time
I make a change to the hour in one of the structs
The change is occurring in the other struct magically....
How do I prevent this from occurring? I need to be able to…

BSchlinker
- 3,401
- 11
- 51
- 82
2
votes
1 answer
Converting localtime to time_t (C++)
I creating date() function on C++ http://aliarth.lt/date.cpp and I got one problem with localtome_to_time() conversion. Does anyone know how that local_time variable:
int time_integer = 12345;
time_t time = (time_t)time_integer;
tm *local_time =…

Alivat
- 51
- 9