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
51
votes
4 answers

precise time measurement

I'm using time.h in C++ to measure the timing of a function. clock_t t = clock(); someFunction(); printf("\nTime taken: %.4fs\n", (float)(clock() - t)/CLOCKS_PER_SEC); however, I'm always getting the time taken as 0.0000. clock() and t when…
Abhishek Thakur
  • 16,337
  • 15
  • 66
  • 97
33
votes
8 answers

Random Boolean Value

I'm trying to generate a random int that is either 0 or 1 in C++. Right now, I receive a 0 every time I run this code, and I'm not sure why. What's the problem here? #include #include srand(time(0)); int randomval = rand() %…
Rich Byden
  • 509
  • 2
  • 6
  • 13
25
votes
9 answers

fprintf and ctime without passing \n from ctime

I have an issue with inserting time in a text file. I use the following code and i get |21,43,1,3,10,5| Wed Feb 01 20:42:32 2012 which is normal but what i WANT TO DO is place the time before the numbers for example like Wed Feb 01 20:42:32 2012 …
BugShotGG
  • 5,008
  • 8
  • 47
  • 63
16
votes
3 answers

How do I get system up time in milliseconds in c++?

How do I get system up time since the start of the system? All I found was time since epoch and nothing else. For example, something like time() in ctime library, but it only gives me a value of seconds since epoch. I want something like time() but…
user3426112
  • 401
  • 1
  • 3
  • 11
15
votes
3 answers

C++ - 'localtime' this function or variable may be unsafe

I am writing a simple logging class in C++ for learning purposes. My code contains a function that returns a string of today's date. However, I get a compiler error whenever 'localtime' is called. std::string get_date_string(time_t *time) { …
ChiefHagno
  • 168
  • 1
  • 1
  • 7
14
votes
2 answers

How to modify 'last status change' (ctime) property of a file in Unix?

I know there's a way to modify both 'modification' (mtime) and 'last access' (atime) time properties of a given file in Unix System by using "touch" command. But I'm wondering whether there exists a way to modify "Last status change" (ctime)…
Emil
  • 555
  • 3
  • 7
  • 16
14
votes
2 answers

What is the difference between and ?

For measuring execution time of a function, I can use both. But what is the difference between using and ? Should I prefer one instead of another?
Yee Liu
  • 1,417
  • 3
  • 15
  • 17
13
votes
3 answers

How to fix missing time related no member in global namespace errors on MacOSX?

I'm trying to compile a project on the command line on Maverick 10.9. The project compiles perfectly on Linux. Apparently, there seems to be an issue with ctime on MacOSX. The errors are $ make Compiling src//core/AbstractARAClient.cpp In file…
user1729210
  • 579
  • 1
  • 8
  • 30
11
votes
3 answers

Does struct tm store time zone information as its data member

Consider the following C++ code #include #include int main() { std::time_t now = std::time(nullptr); struct tm local = *std::localtime(&now); struct tm gm = *std::gmtime(&now); char str[20]; std::strftime(str,…
aafulei
  • 2,085
  • 12
  • 27
11
votes
4 answers

Addition some interval to tm structs

I have one struct tm. And I need to add some fixed interval (given in xx years, xx months, xx days) to the tm struct. Is there any standard function to do this? The compiler I use is MSVC 2005 on Windows XP.
StNickolay
  • 950
  • 2
  • 9
  • 21
11
votes
5 answers

error C4996: 'ctime': This function or variable may be unsafe

I have a large project about static source code analysis, and everything compiles successfully, except for one thing. I have provided the error message in the title. The point that confuses me is that it gives an error message saying unsafe. I…
user1726549
11
votes
1 answer

ctime, mtime, holding directory, windows, linux

Let's clarify this once and for all. I tried to Google this but it seems this information can't be found in one place. When a file is created or removed, the holding directory mtime changes on Windows and Linux both. ctime also changes on Linux bot…
chx
  • 11,270
  • 7
  • 55
  • 129
10
votes
1 answer

Why is it so convoluted to get the date and/or time in C++?

I fully expect this to be closed within a day or two since it's a kinda subjective topic, but here goes anyway: Why does it take at least 5 lines of code to get the date/time in C++? This was one of the first things I learnt how to do in C, but that…
Kenny83
  • 769
  • 12
  • 38
9
votes
4 answers

How can I set a file creation time with ruby on Mac OS?

I'm trying to set the filesystem creation time for a file on Mac OS using a ruby script. On Mac OS X the 'ctime' represents the last time of inode modification rather than the file creation time, thus using ruby's File.utime() to set ctime will not…
djoll
  • 1,139
  • 1
  • 12
  • 31
9
votes
1 answer

Compilation error error C2039: 'clock_t' : is not a member of '`global namespace''

I'm compiling in VS 2010 with boost 1_53. I'm also using boost's threads. during compilation i'm getting bunch of errors like this c:\program files (x86)\microsoft visual studio 10.0\vc\include\ctime(18): error C2039: 'clock_t' : is not a member of…
Nem
  • 336
  • 3
  • 8
  • 22
1
2 3
16 17