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

difftime is returning a wrong number

#include #include using namespace std; int main() { double seconds; struct tm birth = {0}; //10-28-1955 birth.tm_year = 55; birth.tm_mon = 9; birth.tm_mday = 28; birth.tm_sec = 0; struct tm…
Ron
  • 13
  • 3
1
vote
1 answer

Historical time to GMT\UTC with DST

Similar to: Convert historical time to GMT This time my scenario is: I need to convert some string times in the format "2011061411322100" into GMT. The problem is that the times are coming from another PC and is a historical time. So I am not…
Paligulus
  • 493
  • 1
  • 4
  • 14
1
vote
1 answer

How to show time from a time stamp and show current time when I have no argument?

I need to make a function which takes a timestamp (the time in milliseconds, type long) and transforms it into readable time (Y-M-D H:M:S); however, after that, I have to overload the function such that if the function doesn't get a parameter it…
user13363944
1
vote
2 answers

Why am I getting the wrong Age

Just basically doing a project for myself. Basically writing a simple program to show your age and your horoscope sign. I am displaying the output I want except the age is wrong. I'm trying to figure out why. I'm thinking because I'm subtracting the…
Scubba91
  • 11
  • 2
1
vote
1 answer

Update the "last modified date" of a file

I want to set the last modified date of a file to the current date in order to avoid Parcel caching (unfortunately I didn't find a better way). So I wrote that: const fs = require('fs'); const file = 'test.txt'; // save the content of the…
Cl00e9ment
  • 773
  • 1
  • 13
  • 30
1
vote
1 answer

Convert the time string of UTC to IST time in C language

I am looking for the UTC (from RFC3339 format) to IST conversion in C program. But I could not find any generic way to convert the time. Here, I found the shell script to convert the UTC time (in RFC3339 format) to IST and I am trying to implement…
Kirubakaran
  • 378
  • 4
  • 20
1
vote
2 answers

Redefining CLOCKS_PER_SEC to a higher number in Windows 10

GNU C++ Compiler in Windows 10 returns CLOCKS_PER_SEC = 1000, but I need to measure compiling time for an algorithm that goes below millisecond intervals (it's a school project). Is there a way to redefine CLOCKS_PER_SEC to, say, one million (like…
Paul Kim
  • 1,153
  • 1
  • 9
  • 17
1
vote
2 answers

ctime not getting time difference of start/end of loop correctly

I'm trying to have a loop execute for an exact time specified by executionTime. I am using ctime to get this timing, and I need it to be within a few milliseconds of accuracy (which I believe it is). Once that loop runs for the execution time…
Mr.Mips
  • 379
  • 2
  • 18
1
vote
3 answers

C++ Using ctime for random number generator but still getting same number

I am a beginner and I am not fully understanding what I am doing wrong using ctime and variables assigned random numbers. My newCard variable keeps returning the same value each time I call it. Any feedback would be appreciated! This program is…
Lilly B
  • 11
  • 1
  • 2
1
vote
1 answer

ctime_r failed in docker

I have a app in docker, which is multi-thread. And my code to transfer time is as below. FILE *fp = NULL; char buf[256] = {0}; char filename[64] = {0}; long timestamp; char status[16] = {0}; char tbuf[26] = {0}; fp = popen(cmd, "r"); if (fp) { …
lxyscls
  • 297
  • 1
  • 3
  • 17
1
vote
2 answers

Seg fault with time and ctime, when porting from Linux to OSX

I am getting errors compiling code designed for (I believe) Linux on OSX. I have tracked down the issue to this section of code: TIMEVAL = time(NULL); char* TIMESTRING = ctime(&TIMEVAL); TIMESTRING[24]=' '; fprintf(LOG, "[ %20s] ", TIMESTRING); Is…
Bill Cheatham
  • 11,396
  • 17
  • 69
  • 104
1
vote
2 answers

Convert textual date and time to ATL::CTime

Given a textual date and time, for example: Sat, 13 Jan 2018 07:54:39 -0500 (EST) How can I convert it into ATL / MFC CTime? The function should return (in case of my example): CTime(2018,1,13,7,54,39) Either in GMT / UTF or plus the time…
Michael Haephrati
  • 3,660
  • 1
  • 33
  • 56
1
vote
1 answer

Is this a correct way to use the struct tm 'tm_isdst' flag

I am building an application in C++ in which I need Time objects to give access to the current system time. To do this, I use time.h. My two constructors go as follow: Time::Time(bool p_daylightSavingEnabled /* = true */) { time_t rawTime =…
BobMorane
  • 3,870
  • 3
  • 20
  • 42
1
vote
1 answer

Keep track of the timer repeatedly in C++

I've a library which accepts a vector of strings as argument & pushes it to a vector of vector of strings (2D vector). I've a condition that "right from the time 1st row is pushed to the 2D vector the timer should start & for every "X" th…
codeLover
  • 3,720
  • 10
  • 65
  • 121
1
vote
2 answers

Creating a CTime @ 2am doesn't return the correct value (Windows CE, C++)

This goes against all reasonnable logic but when I try to construct a CTime containing '2' for hours, it will return a 1 instead of 2 in the hour field. Only for this hour value. Platform is WindowsCE 6.0, plain c++ (VS2005) void main(void) { …
Philippe Brodeur
  • 131
  • 1
  • 3
  • 8