BUG: Date formats that contain 'gg' for Emperor Era year are not formatted correctly with the COleDateTime class when you set the locale to Japanese on a computer that is running Windows 2000 (826556)



The information in this article applies to:

  • Microsoft Windows 2000 Professional
  • Microsoft Windows 2000 Professional SP1
  • Microsoft Windows 2000 Professional SP2
  • Microsoft Windows 2000 Professional SP3
  • Microsoft Windows 2000 Professional SP4

SYMPTOMS

In Regional options, you set the Date to Japanese, and you set the Long date format to gg yy 'Year' MM 'Month' dd 'Date' on a computer that is running Microsoft Windows 2000 where Year, Month, and Date are in Japanese. When the COleDateTime class is used to output the date, the year that is displayed remains "2004" instead of the Japanese Emperor year "16."

CAUSE

This problem is caused by a bug in the strftime and VarBstrFromDate functions that format the date. These low-level functions cause the COleDateTime class to fail.

WORKAROUND

To work around this problem in Windows 2000, use the Win32 API GetDateFormat funtion. The GetDateFormat function correctly formats the Japanese Emperor Era year. To do this, replace the code in the CMainFrame::CMainFrame() function with the following code:
const MAX_STR = 30; 
char strDate[MAX_STR]; 
SYSTEMTIME time01={2004,1,5,1,1,1,1,1};
GetDateFormat(LOCALE_SYSTEM_DEFAULT,0, &time01,"dddd,dd MMM yyyy",  strDate,MAX_STR); 
MessageBox(strDate,"Date",MB_OK);

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section. This bug was corrected in Microsoft Windows XP.

MORE INFORMATION

Note Before you follow the steps to reproduce the behavior, set your Regional options on a computer that is running Windows 2000 to the settings that are described in the "Symptoms" section. To do this, follow these steps:
  1. In Control Panel, double-click Regional options.
  2. On the General tab, click Japanese in the Language settings for the system list, and then click Japanese in the Your locale (location) list.
  3. Click Set default, click Japanese in the Select the appropriate locale list, and then click OK.
  4. Click OK. You must insert your Windows 2000 installation CD in your CD-Rom drive to complete the installation.
  5. Restart your computer.
  6. Repeat step 1 and step 2, and then click the Date tab.
  7. Click gg yy 'Year' MM 'Month' dd 'Date' in the Long date format list.

    Note 'Year', 'Month', and 'Date' are in Japanese.
  8. Click the first item in Japanese in the Calendar type list, and then click OK.

Steps to reproduce the behavior

  1. Start Microsoft Visual C++ 6.0
  2. On the File menu, click New.
  3. On the Projects tab, click MFC AppWizard (exe).
  4. In the Project Name box, type Q826556.
  5. In the Location box, type C:\Test, and then click OK.
  6. Click Single document in the MFC AppWizard - Step 1 dialog box, and then click Finish.
  7. In the New Project Information dialog box, click OK.
  8. Expand Q826556 Files, expand Source Files, and then double-click MainFrm.cpp.
  9. Add the following include statements in the code window after the #include "MainFrm.h" statement:
    #include "locale.h" 
    
  10. Replace the code in the CMainFrame::CMainFrame() function with the following code:
    setlocale( LC_ALL, "Japanese" );
    COleDateTime localtime(2004,1,1,1,1,1);
    MessageBox(localtime.Format(_T("%A, %B %d, %Y")),"Date",MB_OK);
    
  11. Press F7 to build the project.
  12. Press Ctrl+F5 to run the project.

Result

A dialog box appears that contains the following:xxx, 1x 01, 2004Note x is a placeholder for a Japanese character.

Expected result

A dialog box appears that contains the following: xxx, 1x 01, 16Note x is a placeholder for a Japanese character.

REFERENCES

For more information about how to develop Web-based solutions for Internet Explorer, visit the following Microsoft Developer Network (MSDN) Web sites:

Modification Type:MajorLast Reviewed:7/13/2004
Keywords:kbcode kbMessageBox kbAPI kbbug KB826556 kbAudDeveloper