Questions tagged [time-t]

`time_t` is a Standard-C data type to hold the seconds since UNIX epoch, that since the 1.1.1970.

171 questions
4
votes
1 answer

What will happen when seconds since epoch > LONG_MAX?

For homework, I am writing a program that deals with a lot of time_t objects. I thought about checking them for overflow, but then it occurred to me that if they overflowed we would all be in a might bit of trouble. Is there a plan for this? What…
Ziggy
  • 21,845
  • 28
  • 75
  • 104
4
votes
1 answer

Set time_t to next 10pm in C?

I want to set a time_t variable to the next date/time at 10pm. So for example, if it was 11pm it would set the time_t to the 10pm the next day (23 hours later) or if it was 5pm it would set it to 10pm (in 5 hours). I can think of a number of ways to…
Zeno
  • 1,769
  • 7
  • 33
  • 61
4
votes
3 answers

fastest way to get time_t from YYYYMMDDHHMMSS string

Is this legit? Im trying to get to a time_t as fast as possible given a string formatted like YYYYMMDDHHMMSS. static time_t ConvertToSecSince1970(char *szYYYYMMDDHHMMSS) { struct tm Tm; memset(&Tm, 0, sizeof(Tm)); Tm.tm_year =…
johnnycrash
  • 5,184
  • 5
  • 34
  • 58
4
votes
2 answers

Convert a C++ time_t to Delphi TDateTime

In a Delphi XE application, I am reading values from a database originally created by a C++ program. There is a date column, stored (it would appear) as time_t, i.e. Unix time, the number of seconds since 00:00, Jan 1, 1970 UTC. I can deal with the…
Marek Jedliński
  • 7,088
  • 11
  • 47
  • 57
4
votes
2 answers

Use struct tm to print a specific date and strftime

So I need to specifically use struct tm to print out my birthday, which I did successfully. However, I am also required to use strftime() to print it in different formats. That's where I encounter my problem, as strftime() only recognizes pointer…
Duc Nguyen
  • 87
  • 2
  • 9
4
votes
4 answers

Is there a diffrence between time_t now=time(NULL); and time_t now; time(&now);?

Both work correctly in my simple test code, but I'd like to know if there is any real difference, or any agreed upon preferences in coding styles. Sample code enclosed: #include #include int main(int argc, char **argv) { …
Dani_l
  • 613
  • 5
  • 14
4
votes
3 answers

calendar time stored as a signed 32-bit integer - when will it overflow

I'm going through exercises from Advanced Programming in Unix and encountered the following question: If the calendar time is stored as a signed 32-bit integer, in which year will it overflow? positive signed integer = 2147483647 In the following…
dcrearer
  • 1,972
  • 4
  • 24
  • 48
4
votes
1 answer

_USE_32BIT_TIME_T equivalent for gcc

On Visual studio I can force use of 32-bit time_t by declaring _USE_32BIT_TIME_T. Is there a similar equivalent for gcc? or is it always 32-bit or is it always 64-bit?
AppDeveloper
  • 927
  • 11
  • 21
4
votes
2 answers

How to printf a time_t variable as a floating point number?

I'm using a time_t variable in C (openMP enviroment) to keep cpu execution time...I define a float value sum_tot_time to sum time for all cpu's...I mean sum_tot_time is the sum of cpu's time_t values. The problem is that printing the value…
soneangel
  • 621
  • 3
  • 10
  • 22
4
votes
4 answers

Comparing time_t values using comparison operators

I have 2 time_t values and I want to find out which one is greater. time_t is internally __int64 on my platform. Can I use <, > and == operators to compare the values? I don't want to know the difference between the two time values. The code will…
51k
  • 1,381
  • 3
  • 12
  • 22
4
votes
2 answers

Convert time_t To Integer

How should I modify this code to print("Its Midnight") every 00:00AM ? #include #include int main(void) { struct tm * localtime ( const time_t * ptr_time ); struct tm { int tm_sec; /* segundos, range 0 to 59 …
Neto
  • 113
  • 1
  • 2
  • 11
4
votes
3 answers

clock() returning a negative value in C

I'm using a quite simple code to measure for time of execution.It works well until I am not sure may be not more than 20 minutes.But after(>20min.)it is returning negative results.I searched throughout the forums and tried everything like changing…
pylearner
  • 63
  • 1
  • 7
4
votes
6 answers

Segmentation fault on time(0);

I'm rewriting an old program to do some new stuff, and suddenly I get a segmentation fault error on the following line of code: time_t seconds_since_time_begun = time(0); Why, oh why? Update: I have included the time.h header file in my code, and…
o01
  • 5,191
  • 10
  • 44
  • 85
4
votes
1 answer

c++ time_t going back before 1/1/1970

i have a c++ code by which i can compute/manipulate starting from an input excel date (by manipulate i mean i can increase/decrease the input date by specific increments or do other computations on it). i use the variable time_t in my code.…
user1612986
  • 1,373
  • 3
  • 22
  • 38
4
votes
4 answers

A way to return error with time_t function in C

I'm currently writing a C function that return a time_t value but I need to manage error cases (because this function uses I/O functions) too. Is it correct to use (time_t) -1 as an error indicator?
Guid
  • 2,137
  • 2
  • 20
  • 33
1 2
3
11 12