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
8
votes
3 answers

How do I printf a date in C?

I'm trying to print a date from a string like "01/01/01" and get something like "Monday First January 2001. I found something with the man of ctime but really don't get it how to use it. Any help ? Thanks,
Difender
  • 495
  • 2
  • 5
  • 18
7
votes
1 answer

How to set a file's ctime with Python?

How can I set a Unix file's ctime? (I'd much prefer an answer in terms of Python. If there's no way to do it with standard Python, then I suppose C is OK too.) (Note: I know that one can use os.utime to set a file's atime and mtime. I am…
kjo
  • 33,683
  • 52
  • 148
  • 265
6
votes
3 answers

MFC measure function in milliseconds

How can i count the millisecond a certain function (called repeatedly) takes ? I thought of: CTime::GetCurrentTM() before, CTime::GetCurrentTM() after, And then insert the result to CTimeSpan diff = after - before. Finally store that diff to…
ilansch
  • 4,784
  • 7
  • 47
  • 96
6
votes
2 answers

Formatting Unix timestamp with ctime in c

I'm trying to format a 10-digit Unix time stamp (currently a string) using ctime. However, ctime() expects a parameter of type time_t, not a string. What must I do before I can use ctime? In other words, can I easily convert the string into a…
jwheels
  • 517
  • 1
  • 7
  • 23
5
votes
3 answers

how to correctly use ctime() to print different time stamps

I was expecting the following code should print different time stamps t1 and t2, however the result shows t1 and t2 are the same. Where did I make the mistake? #include #include using namespace std; int main() { time_t t1 =…
daydayup
  • 2,049
  • 5
  • 22
  • 47
5
votes
2 answers

Convert long int to const time_t

I have variable tmit: long tmit;. I got error in this code: printf("Time: %s",ctime(&tmit)); And error say: Cannot convert 'long int*' to 'const time_t* {aka const long long int*}' for argument '1' to 'char* ctime(const time_t*)' My question is,…
Nejc Galof
  • 2,538
  • 3
  • 31
  • 70
5
votes
2 answers

How to neatly initialize struct tm from ctime

Consider these two ways to get an epoch time from a date formatted as a string: #include int main() { struct tm tm_init = {0}; strptime("2012-10-26 16:00", "%Y-%m-%dT %H:%M", &tm_init); long epoch = mktime(&tm_init); …
Herbert
  • 5,279
  • 5
  • 44
  • 69
4
votes
1 answer

Understand successive call to ctime()

I have a question about how the glibc ctime() works. Follows my snippet: #include #include #include int main (int argc,char** argv) { int ret=EXIT_SUCCESS; time_t tm1; time_t tm2; tm1 =…
hadibou
  • 328
  • 3
  • 8
4
votes
2 answers

ctime on iOS device not measuring time properly

I need to calculate the time that a piece of my code takes to execute, right now I am using clock_t like so: clock_t start = clock(); /* Do something here */ float executionTime = (clock()-(float)start) / CLOCKS_PER_SEC; This works in the…
A Person
  • 801
  • 1
  • 10
  • 22
4
votes
1 answer

How to display a timer simultaneously with the rest of the program?

So I've been making a terminal-based quiz as my first-year project, I decided to display a timer along with the code, but the timer doesn't let the program proceed cause of the infinite loop used in the timer. How do I proceed through this problem? …
Subjugator
  • 43
  • 4
4
votes
1 answer

Formatted timestring when parsed to a time_point gives an hour difference

I found the following problem. I have a string with a time (gotten from a file to which I putoutted using the reverse operations). However, when converting this to a time_point and outputting it to terminal, I find a difference of one hour. I have…
jelmew
  • 543
  • 1
  • 7
  • 15
4
votes
3 answers

C: How to print a particular `time` value in a particular timezone (by offset)?

I'm writing an application in C that parses data files recorded by an external program (over which I have no control). It's storing binary data, one field of which is a time in standard UNIX "epoch" format (seconds since January 1st, 1970,…
lindes
  • 9,854
  • 3
  • 33
  • 45
4
votes
1 answer

Linux find files where mtime and ctime are not equal

Can I do a find and list files where ctime and mtime are not equal? find . -type f -name '*.php' -ctime -5 MISSING_PART MISSING_PART: something like -mtime != -ctime
Tillebeck
  • 3,493
  • 7
  • 42
  • 63
4
votes
6 answers

Initializing static struct tm in a class

I would like to use the tm struct as a static variable in a class. Spent a whole day reading and trying but it still can't work :( Would appreciate if someone could point out what I was doing wrong In my class, under Public, i have declared it…
eruina
  • 853
  • 3
  • 9
  • 18
4
votes
1 answer

How does the clock() function in access the system clock?

I'm using an STM32 microcontroller with minimal libraries attached. I'd like to use the clock() function from (and potentially the new std::chrono) but I'm stuck at clock() returning -1. This isn't surprising, since I don't expect the…
Eric
  • 95,302
  • 53
  • 242
  • 374
1
2
3
16 17