Any particular type of object? Are you writing your own from scratch, for an exercise? Are you able to use existing libraries? Are there any particular retrictions? Does it have to start from 1 Jan 2000?
Any particular type of object? Are you writing your own from scratch, for an exercise?
a. I just need to print a date in form of mm/dd/yyyy format. I dont want to write from scratch. I would like to use exisitng functions if any are available.
Does it have to start from 1 Jan 2000?
A. Yes, it has to start from 1 Jan 2000
Well, if you are happy to apply an offset to account for the difference between your start date and theirs, you could use one of the existing types and its associated functions.
(I didn't ask if you were using Windows or Linux or??)
The types readily available to Windows programs are:
* The Automation DATE type -- which I think is the COM date type that webJose is referring to -- "is implemented as a floating-point value, measuring days from midnight, 30 December 1899"
* (if you're using C++/CLI) The System.DateTime in .Net is "measured in 100-nanosecond units called ticks, and a particular date is the number of ticks since 12:00 midnight, January 1, 0001 A.D."
* The WIN32 FILETIME is "a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601."
* And time_t is the number of "seconds elapsed since midnight, January 1, 1970"
(Linux also has timeval and timespec which uses the same second count as time_t, but adds to it usecs and nsecs repectively)
(I've ignored the struct types, like SYSTEMTIME and struct tm, for the moment. The sec/etc counts are easier to map directly to day counts)