作者:Alex.Duan 日期:2019-09-09
TDateTime t;
// 获取当前日期及时间:
t = TDateTime::CurrentDateTime();
// 获取当前日期:
t = TDateTime::CurrentDate();
// 获取当前时间:
t = TDateTime::CurrentTime();
// 转换成年月日
unsigned short year, month, day;
t.DecodeDate(&year, &month, &day);
// 转换成时分秒
unsigned short hour, min, sec, msec;
t.DecodeTime(&year, &min, &sec, &msec);
// 通过数值设置指定日期
t = TDateTime(2019, 9, 9);
// 通过数值设置指定时间:时,分,秒,毫秒
t = TDateTime(9, 9, 9, 0); //
// 设置日期时间:年月日时分秒毫秒
t = TDateTime(2019, 9, 9, 9, 9, 9, 0);
// 通过时间戳设置,从1899年12月30日起按天计数
// 整数表示天数,小数表示时间,0.5表示12小时
t = TDateTime(0.5);
// 字符串转日期及时间
t = StrToDateTime(L"2019/09/09 09:09:09");
t = StrToDate(L"2019/09/09");
t = StrToTime(L"23:45:56");
// 获取星期几
int dow = DayOfWeek(t);