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
4
votes
1 answer

Where and how does ctime allocate memory?

I'm using ctime function to get a readable representation of time_t variable. ctime is declared as follows: char *ctime (const time_t *timer); and you can see that it returns a pointer to the resulting char array without any char pointer passed in…
tonytony
  • 1,994
  • 3
  • 20
  • 27
3
votes
1 answer

What are the disadvantages to using ctime's tzset?

In a question about getting a system's time zone, this answer did not get up-voted. It suggests the use of tzset() and some system globals (e.g. daylight, timezone, and tzname) from time.h. After some testing, I was able to get accurate results from…
Elliot Cameron
  • 5,235
  • 2
  • 27
  • 34
3
votes
2 answers

want to convert ColeDateTime to CTime

I am reading a datetime from database in a ColeDateTime format. I want to convert it to CTime to get the date month year and time. CString repDt; //**this will hold the datetime which i read from Database** COleDateTime dt; //**my datetime format…
sshah
  • 63
  • 1
  • 5
3
votes
1 answer

Alternative to time() function

MISRA and AUTOSAR do not allow us to use the time() function of (and ). Rule 18-0-4: The time handling functions of library shall not be used. Is there an alternative to the time() function in C++? There is the time library…
KplnMoon
  • 151
  • 1
  • 10
3
votes
1 answer

`entr`: How is update ID'd? noatime troubles? &, why -r not work with -d?

I have a script regularly appending to a log file. When I use entr (discovered here) to monitor that log file, and I then touch the log, everything works fine, but when the script appends to the file, entr fails. This may be because I have noatime…
Diagon
  • 473
  • 5
  • 16
3
votes
1 answer

real time vs. cpu time performance measure

I'm trying to do some performance measures in c++ by measuring the real elapsed time in milliseconds vs. the cpu time in milliseconds. This is how my code looks like: auto start = std::chrono::high_resolution_clock::now(); unsigned begin =…
Ben
  • 4,486
  • 6
  • 33
  • 48
3
votes
2 answers

C++, MingW, ctime, nanosleep() not found?

I just wanted to use nanosleep() but it seems not to be available in MingW ctime: #include //this is what I need, isn't it? How can I use nanosleep on MingW? Thanks.
blubberbernd
  • 3,641
  • 8
  • 35
  • 46
3
votes
1 answer

Python time.ctime() format: 0-padding or space-padding

Two different computers (same python version) return different formatting for time.ctime(). One returns "Sun May 6 14:04:28 2018" with 2 spaces before the day of month; the other returns "Sun May 06 14:04:28 2018" with a space and a zero. I feel…
3
votes
1 answer

How to simulate the passage of time to debug a program?

I'm writing a C++ program that keeps track of dates whenever it's ran, keeping a record. I want to test and debug this record keeping functionality, but the records themselves can span years; letting time pass naturally to expose bugs would take...…
Anne Quinn
  • 12,609
  • 8
  • 54
  • 101
3
votes
4 answers

Pass system date and time as a filename in C++

I wanted to make an Attendance system which would take system date and time as file name of the file for ex: this is how normally it is int main () { time_t t = time(0); // get time now struct tm * now = localtime( & t ); cout << (now->tm_year +…
Chinmay Wankar
  • 35
  • 1
  • 1
  • 5
3
votes
3 answers

Size of struct tm

I printed sizeof(struct tm) in C using sizeof() operator it gives me 44 bytes.But in man page of ctime it has 9 int variables for time.then its size should be 36. How it is giving 44?
Radha
  • 53
  • 1
  • 8
2
votes
3 answers

getdate and ctime not working properly

Here is my program time_play.c : #include #include #include int main (void) { char *time_str = "2011-07-20 17:30:18"; time_t time_tm = getdate(time_str); printf("str: %s and time: %s \n", time_str,…
hari
  • 9,439
  • 27
  • 76
  • 110
2
votes
1 answer

How to convert dd-mmm-yyyy and now() to days?

I need convert a dd-mmm-year string to epoch days to do some simple math. Specifically, calculate the number of days from now() to the date of the string. I'm looking at and but am not seeing an obvious way to do that? How do you…
buttonsrtoys
  • 2,359
  • 3
  • 32
  • 52
2
votes
1 answer

debugfs set_inode_field ctime with nanoseconds

I'm using debugfs to change the ctime of a file (programm rotine attached to ctime of this specific file) on an ext4 file system. The therefor used command is: debugfs -w -R 'set_inode_field foo/bar ctime 20130503145204' /dev/vdb1 but this is…
cnbhl
  • 41
  • 4
2
votes
3 answers

Convert historical time to GMT

I need to convert some string times in the format "2011061411322100" into GMT - my first attempt is below. However, the problem is that the times are coming from another PC and is a historical time. So I am not getting the times in real time so I…
Paligulus
  • 493
  • 1
  • 4
  • 14
1 2
3
16 17