Questions tagged [ctime]

CTime Class The upper date limit is 12/31/3000. The lower limit is 1/1/1970 12:00:00 AM GMT.

CTime does not have a base class.

CTime values are based on coordinated universal time (UTC), which is equivalent to Greenwich mean time (GMT). The local time zone is controlled by the TZ environment variable.

When creating a CTime object, set the nDST parameter to 0 to indicate that standard time is in effect, or to a value greater than 0 to indicate that daylight savings time is in effect, or to a value less than zero to have the C run-time library code compute whether standard time or daylight savings time is in effect. tm_isdst is a required field. If not set, its value is undefined and the return value from mktime is unpredictable. If timeptr points to a tm structure returned by a previous call to asctime, gmtime, or localtime, the tm_isdst field contains the correct value.

A companion class, CTimeSpan, represents a time interval.

The CTime and CTimeSpan classes are not designed for derivation. Because there are no virtual functions, the size of CTime and CTimeSpan objects is exactly 8 bytes. Most member functions are inline.

252 questions
2
votes
2 answers

C++ Time returned is two hours out

Bit of a c++ newbie so here we go; I have a method that is parsing a date/time, however that date/time is passed to me always with 00:00:00 as the hh:mm:ss. As such i want to add in the values of the current systime in place of those values. I have…
Graham
  • 651
  • 2
  • 10
  • 23
2
votes
1 answer

"Daylight Savings Time" in DOS

I am using the time(NULL) function in a C application to get the seconds since 1970. I've noticed that it is returning the information with 1 hour of difference. then I tried to convert the result to a tmstructure using localtime, and then I noticed…
Renan Greinert
  • 3,376
  • 3
  • 19
  • 29
2
votes
2 answers

How do you include time_t on an Arduino?

I am trying to compile and upload one of the example WiFly projects to my Arduino. One of the example's functions is has return-type 'time_t', but the compiler doesn't recognize that. I have tried including both and . This is my…
Sponge Bob
  • 1,551
  • 5
  • 17
  • 23
2
votes
3 answers

ctime() and date/time conversion

I know, this particular kind of thing has been answered a number of times, but I think, my question here is more to do with general C++ stuff than ctime() or date/time conversion. I just happened to try it out with this. So, here is the code: …
MacUsers
  • 2,091
  • 3
  • 35
  • 56
1
vote
2 answers

ctime() causing SIGABRT (?!)

This is the code: void i_log_ (int error, const char * file, int line, const char * fmt, ...) { /* Get error description */ char * str_err = get_str_error (errno); remove_trailing_newl (str_err); /* Format string and parameters…
Metz
  • 675
  • 1
  • 9
  • 17
1
vote
2 answers

Timing a function in microseconds

Hey guys I'm trying to time some search functions I wrote in microseconds, and it needs to take long enough to get it to show 2 significant digits. I wrote this code to time my search function but it seems to go too fast. I always end up getting 0…
Jonathan
  • 167
  • 10
1
vote
1 answer

How to prevent unique pointers from overlapping

I'm trying to build a timer in C++. In my Timer class there are two Date objects that hold a std::unique_ptr pointer. After I std::move the second unique_ptr in the second Date object in the following piece of code, it points to the same…
loremol
  • 25
  • 4
1
vote
1 answer

C program function ctime() returns wrong time/date - out by 3 days

#include #include int main(void){ time_t now = time(NULL); printf("%s\n", ctime(&now)); return 0; } This is compiled using GCC and run. Result: Wed May 10 19:13:18 2023 Actual: Sat May 13 09:45:37 2023 (PC system time…
Dabbo
  • 143
  • 5
1
vote
1 answer

What is the best way to store CTime in mysql database?

Using the shell command I get the following output with the CTime for a particular file: 1665579792.879379. Now I'm thinking about the best way to save this value to msql database, and what type of column to create. Because when I do something like…
Helen
  • 463
  • 2
  • 9
  • 23
1
vote
3 answers

mktime() for non-local timezone

In C the function mktime() returns the epoch time according to the local timezone (the input struct is locally formatted). The function timegm() returns the epoch time according to the UTC time (the input struct is formatted based off of UTC…
NorthStar
  • 81
  • 9
1
vote
0 answers

Conversion of Local Time to GMT/UTC, and back GMT/UTC to Local Time in C++

The problem of conversion from GMT/UTC to local time in C++ is tricky because of daylight saving. To solve the daylight saving problem there must be a table for every country and zone, since daylight saving is not universal. This problem/solution is…
PKallback
  • 11
  • 1
1
vote
1 answer

How to get the expiration date based on week code not on current date using c++

How will I get the expiration date of an item, which is based on week code? Whenever I run the code that I made, the program reads the current date and disregards the week code. For example: Week Code: 2138 (2021 week 38) Shelf_life : 6…
PJiwon
  • 50
  • 5
1
vote
1 answer

How to deal with ctime includes within the scope of a class in CPP?

I want to use inside the scope of a class in C++. However, whenever I try to compile the following class, I get the error: error: 'time' cannot be used as a function time_t now = time(0); I think it may be something related to the…
Breno
  • 135
  • 8
1
vote
1 answer

Is it possible to print the same timestamp as NSLog small within a macro?

I want to make a custom NSLog() that logs to a file and I want to ship with it. NSLog also prints to the system log. I don't want that on the users machine. So I have to roll my own. Thats fine but: Exceptions (which get logged to a different file)…
david
  • 3,553
  • 4
  • 28
  • 39
1
vote
1 answer

Recording how much time is required to run a portion of code and store it to an array in C++

Need help in recording time taken to run several parts of code in C++. I need to store these times to an array for use later. In MATLAB I would do something like this; for i=1 : n tic this is some stuff I want to run(); array[1,i] =…
AdamsK
  • 33
  • 4