C++ Convert from packed DATE to CTime
I have looked but cannot find the API to co开发者_开发问答nvert from DATE to CTime and vice versa. Is there such a thing?
There's probably a shorter method, but going by the docs you can store a DATE in a COleDateTime, get that as a SYSTEMTIME and then use that to construct your CTime. Assuming it's representable as a CTime.
SYSTEMTIME st;
DATE d(whatever);
COleDateTime ole(d);
d.GetAsSystemTime(st);
CTime ct(st);
CTime include a number of constructors and converters for various time formats; it seems odd that DATE
is not included. However _time64_t
is supported, and differs from DATE
only in the starting date and scale. You can easily convert from one to another if you have the starting date of January 1, 1970 as a DATE
value:
DATE jan1_1970 = ????;
__time64_t t;
DATE d;
double seconds_per_day = 24.*60.*60.;
t = (d - jan1_1970) * seconds_per_day;
d = (t / seconds_per_day) + jan1_1970;
精彩评论