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

Merge Sort for 10 million inputs

This is my code in c++. I have used c++11. is used to measure time in microseconds. My merge sort takes about 24 seconds to sort a randomly generated number array of size of 10 million. But when i refer to my friend's results they have got like 3…
user4306253
2
votes
1 answer

difftime returns strange value on particular date

I don't understand why difftime returns a strange value, so here is the dataset and the code I am using. Code : struct tm currentTime; currentTime.tm_year = 2014 - 1900; currentTime.tm_mon = 9 - 1; currentTime.tm_mday = 6; currentTime.tm_hour =…
Jonathan Taws
  • 1,168
  • 11
  • 24
2
votes
2 answers

parse localtime in c++

Is there an easy "beginner" way to take the current time using to a Date object that has int month int day int year for it's member variables? Thanks.
Crystal
  • 28,460
  • 62
  • 219
  • 393
2
votes
2 answers

Is it possible to insert the build time into an application?

A game has this: I'm curious to whether this was the actual build time, and sure enough, the 'File Last Modified' date of Crysis.exe (the program) is 03/31/2009, 01:40. Sure, the developer could easily have manually inputted that value, and built…
AStopher
  • 4,207
  • 11
  • 50
  • 75
2
votes
5 answers

Unix time as int to local time

I have a function which returns a timestamp in unix time as int. I need to convert this int to a string dd/mm/yy in local time. The "local" part is causing me problems, if it weren't for that, I could have just made my own function to convert it. I…
user129186
  • 1,156
  • 2
  • 14
  • 30
2
votes
4 answers

Has anyone implemented __getzone() for IAR Embedded Workbench for MSP430?

I am having to deal with some time conversions in my application. I would like to stick to using standard library functions as much as possible. Right now I am using a time_t structure as my system time base. However, some devices can sync time to…
Nick
  • 1,361
  • 1
  • 14
  • 42
2
votes
1 answer

Using rand() and srand() in C++

I made a class with a function that returns a randomly generated pair to represent a coordinate pair. At the beginning of the function I have srand(time(NULL)) and I use rand() % 50 to get the random number pair. It works great... as long…
UnworthyToast
  • 825
  • 5
  • 11
  • 21
2
votes
4 answers

c/c++ microsecond timestamp

I used this piece of code to get timestamp in microsecond in c/c++. but it doesn't look like microsecond. also i don't know if there is any way to format it. timeval curTime; gettimeofday(&curTime, NULL); int milli = curTime.tv_usec /…
bbc
  • 1,061
  • 4
  • 13
  • 21
2
votes
3 answers

Date handling before 1970 c++

I was wondering what is the best thing to do here. I was given an assignment and I have to update a Date class that uses Ctime. The class must now work for date before 1970. I was looking around and I didn't find much... So I guess my question is…
SKTLZ
  • 163
  • 1
  • 4
  • 12
2
votes
5 answers

How to select random letters in c++

Hi I'm working on an hangman project for my final in my c++ class. I've got most of it working but I wanted to make it so the player could have the option to play against a computer opponent in single player mode. I tried doing something like…
user2340686
  • 97
  • 1
  • 3
  • 11
2
votes
1 answer

what is the exact time to run a program?

I want the exact time to run a program, I use it from clock(). But there is a problem that I can not give an exact time for small n like 2000. I want it to return the correct answer for n=1000. #include #include #include…
2
votes
1 answer

Does ctime return the Gregorian calendar date?

Does the standard C ctime function return the Gregorian calendar date? In particular, I want to verify that it will account for leap years and thus display Feb 29 for the respective dates.
Vilhelm Gray
  • 11,516
  • 10
  • 61
  • 114
2
votes
2 answers

Convert milliseconds to time_t

I have the number of milliseconds starting from 2004 to a specific date. I want to convert this to time_t to display it with ctime()? Perhaps there is another method to visualize the date by this milliseconds timestamp, does anyone have one?
illvoid
  • 43
  • 1
  • 7
2
votes
2 answers

Time since epoch is -1

I am trying to get the number of seconds that have elapsed since epoch. The code: long parseTime(string time) { cout << "Time entered = " << time << endl; long timeSinceEpoch; //takes in time in string format - date + time and returns…
Sriram
  • 10,298
  • 21
  • 83
  • 136
2
votes
1 answer

Dealing with daylight savings time - C++

Given an input date and time (in string format), I am trying to get the epoch time for it using time functions given in ctime like mktime. Converting the time_t epoch time back to a date and time results in a date and time that is one hour less than…
Sriram
  • 10,298
  • 21
  • 83
  • 136