wrote:
> I met across a datetime problem when I tried to translate some delphi
> code to cpp.
> There's a struct called TTimeStamp in delphi,
> and this is the cpp equivalent:
>
> struct TTimeStamp
> {
> int Time; // the number of milliseconds that have elapsed since
> midnight
> int Date; // the number of days since 1/1/0001 plus one
> };
>
> My question is, I can only get the current date and time in cpp,
> how can I figure out the corresponding TTimeStamp of the current time?
Well, you can always do a little maths. Each year is 365 days,
each day is 86400000 ms.
Things to remember:
- leap years have a day extra (every 4 years, except when the year
is divisible by 100 and not by 400),
- change of calendar from Julian to Gregorian, if you need dates
from long ago,
- lack of year 0, if you need BCE dates,
- if you are really pedantic about this, additions of 61-st
second on New Years Day Eve, from time to time.
HTH,
- J.