CTime tm = CTime::GetCurrentTime();
CString tmstr, WeekDay;
WeekDay = GetWeekDay();
tmstr.Format(_T("%04d-%02d-%02d %02d:%02d:%02d %s"), tm.GetYear(), tm.GetMonth(), tm.GetDay(), tm.GetHour(), tm.GetMinute(), tm.GetSecond(), WeekDay);
CString CMyTestDlg::GetWeekDay()
{
COleDateTime t, tWeekBegin, tWeekEnd;
t = COleDateTime::GetCurrentTime();
// t.SetDate(2013,3,24);
/*!<这里需要注意的是西方人的习惯和我们不一样,他们把星期天当做*/
/*!<每个星期的第一天,如下面的函数GetDayOfWeek就是如此,所以我做了下面的一些转换*/
int nWeek = t.GetDayOfWeek();
COleDateTimeSpan tsWeekBegin,tsWeekEnd;
if(1 == nWeek)
{
tsWeekBegin.SetDateTimeSpan(6, 0, 0, 0);
tsWeekEnd.SetDateTimeSpan(0, 0, 0, 0);
}
else
{
tsWeekBegin.SetDateTimeSpan(nWeek - 2, 0, 0, 0);
tsWeekEnd.SetDateTimeSpan(8 - nWeek, 0, 0, 0);
}
tWeekBegin = t - tsWeekBegin;
tWeekEnd = t + tsWeekEnd;
CString str, str1, str2, WeekDayT;
str = t.Format(L"%Y-%m-%d");
str1 = tWeekBegin.Format(L"%Y-%m-%d");
str2 = tWeekEnd.Format(L"%Y-%m-%d");
int f_num = tWeekBegin.GetDay();
int t_num = t.GetDay();
int l_num = tWeekEnd.GetDay();
int num = t_num - f_num + 1;
switch (num)
{
case 1:
WeekDayT = _T("星期一");
break;
case 2:
WeekDayT = _T("星期二");
break;
case 3:
WeekDayT = _T("星期三");
break;
case 4:
WeekDayT = _T("星期四");
break;
case 5:
WeekDayT = _T("星期五");
break;
case 6:
WeekDayT = _T("星期六");
break;
case 7:
WeekDayT = _T("星期天");
break;
default:
break;
}
return WeekDayT;
}