MFC星期显示本地化

在MFC中使用CTime类的 GetDayOfWeek 成员函数和 GetLocaleInfo 函数可以以本地化形式获得某个时间对应的星期字符串,实现星期数据以中文等形式显示。

MFC代码:

UINT DayOfWeek[] = {
   LOCALE_SDAYNAME7,   // Sunday
   LOCALE_SDAYNAME1,   
   LOCALE_SDAYNAME2,
   LOCALE_SDAYNAME3,
   LOCALE_SDAYNAME4, 
   LOCALE_SDAYNAME5, 
   LOCALE_SDAYNAME6   // Saturday
};
TCHAR strWeekday[256];
CTime time(CTime::GetCurrentTime());   // Initialize CTime with current time
::GetLocaleInfo(LOCALE_USER_DEFAULT,   // Get string for day of the week from system
   DayOfWeek[time.GetDayOfWeek()-1],   // Get day of week from CTime
   strWeekday, sizeof(strWeekday) / sizeof(strWeekday[0]));
ATLTRACE(_T("%sn"), strWeekday);               // Print out day of the week

参见MSDN:http://msdn.microsoft.com/en-us/library/1wzak8d0(v=vs.110).aspx

发表评论

电子邮件地址不会被公开。