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

Why is C struct tm (time.h) returning the wrong month?

It is currently April 10th, 2020. I made this integer month to string month converter function in C. It takes in an integer and returns a string. For some reason, it thinks it is March. I investigated into whether the problem was my converter or…
Serket
  • 3,785
  • 3
  • 14
  • 45
2
votes
2 answers

Why does the change time(ctime) of a directory change when creating a new file in it?

According to the documentation: Change time (ctime) This marks when a file's metadata was changed, such as permissions or ownership. This is also known as the "update" time in some documentation. Yet when I create a new file in a directory and…
Roland
  • 7,525
  • 13
  • 61
  • 124
2
votes
3 answers

ctime returning null

If the user type time_t is defined as __darwin_time_t, which itself is defined as long in MacOS X, why does the following code outputs 8 Time is (null)? Maybe it's something silly, but I can't really understand it. #include #include…
sidyll
  • 57,726
  • 14
  • 108
  • 151
2
votes
2 answers

Get interval between 2 operations using ctime?

I am interested in showing the execution time for a program in C, at diverse points, using ctime. I have tried something like that, but it must not be right... int main() { time_t tm1, tm2; tm1 = time(NULL); sleep(2); tm2 =…
Madrugada
  • 1,261
  • 8
  • 24
  • 44
2
votes
3 answers

Implicit conversion double to unsigned long overflow c++

I'm testing a timer based on the ctime library using the clock() function. Please note that the code that follows is only for test purposes. #include unsigned long Elapsed(void); clock_t start = 0; clock_t stop = 0; int main() { start =…
Podarce
  • 473
  • 1
  • 6
  • 22
2
votes
1 answer

struct tm time; vs tm time = {}. Same output but not the same?

I was doing some programming questions on this website called Kattis. Here is a link to the question I was doing: https://open.kattis.com/problems/datum While I was trying to solve this, I found out something very, very, very weird. Before I begin,…
A. Park
  • 94
  • 1
  • 10
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
2 answers

Convert ctime to unicode and unicode to ctime python

I have converted a ctime value to unicode 1295478503.6789999 to 'Wed Jan 19 18:08:23 2011' Can I go backwards? From the second line to the first?
2
votes
3 answers

strftime returns incorrect day of the week on iOS

I have the following code: #include #include using namespace std; int main() { tm _tm; strptime("2017-04-17", "%Y-%m-%d", &_tm); char buf[16]; strftime(buf, sizeof(buf), "%A", &_tm); cout << buf <<…
aardvarkk
  • 14,955
  • 7
  • 67
  • 96
2
votes
1 answer

Time spends in CPU faster than in reality

I am wondering why my entire application runs in less than 8 seconds while the time obtained from clock_gettime is 19.3468 seconds which is more than two times as much as what happens in reality. Where is the problem…
ar2015
  • 5,558
  • 8
  • 53
  • 110
2
votes
2 answers

Directly setting values of struct tm's attributes not working

Why does asctime(ptr) return nothing? All the variables of the struct have values. Can someone explain why does this happen? I also tried using strftime but the result was the same. #include #include #include //#include…
MattSt
  • 1,024
  • 2
  • 16
  • 35
2
votes
3 answers

C++ and mktime: 26/6/1943 and 27/6/1943 are the same day

It's a strange situation. Check out this Coliru code: #include #include #include using namespace std; #define SEGS 60 #define MINS 60 #define HOURS 24 int days(tm* date1, tm* date2) { return (mktime(date1) -…
ABu
  • 10,423
  • 6
  • 52
  • 103
2
votes
1 answer

Can't verify the conversion from time_point to tm and tm back to time_point

I created a current time_point and converted it to structure tm and printed it's values. Now converted this tm structure to time_point. On comparing the first and second time_points, it is telling that they're different. But the values of structure…
Naresh T
  • 309
  • 2
  • 14
2
votes
2 answers

Human readable string of 64bits time_t value

I'm trying to print out the date, in a human readable format, for the maximum time_t value possible. The following code seems to work just fine on 32bits machines (initializing m_time with 0x7fffffff), but it outputs null for the theoretically…
pbn
  • 112
  • 10
2
votes
2 answers

Is There an Upper Bound in my locale for Time Related Information?

Is there a definition somewhere in the standard namespace that sets forward: Months in a year Days in a week Hours in a day Minutes in an hour Seconds in a minute The struct tm has contains member variables that must be in these ranges, but I…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288