Microsoft KB Archive/826556

= 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 =

Article ID: 826556

Article Last Modified on 11/26/2007

-

APPLIES TO


 * Microsoft Windows 2000 Professional Edition
 * Microsoft Windows 2000 Service Pack 1
 * Microsoft Windows 2000 Service Pack 2
 * Microsoft Windows 2000 Service Pack 3
 * Microsoft Windows 2000 Professional Edition

-



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



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,&quot;dddd,dd MMM yyyy&quot;, strDate,MAX_STR); MessageBox(strDate,&quot;Date&quot;,MB_OK);



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; 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 &quot;Symptoms&quot; 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   MM   dd   in the Long date format list.

Note,  , and   are in Japanese.
 * 1) Click the first item in Japanese in the Calendar type list, and then click OK.

Steps to reproduce the behavior
 Start Microsoft Visual C++ 6.0 On the File menu, click New. On the Projects tab, click MFC AppWizard (exe). In the Project Name box, type Q826556 . In the Location box, type C:\Test, and then click OK. Click Single document in the MFC AppWizard – Step 1 dialog box, and then click Finish.</li> In the New Project Information dialog box, click OK.</li> Expand Q826556 Files, expand Source Files, and then double-click MainFrm.cpp.</li>  Add the following include statements in the code window after the #include &quot;MainFrm.h&quot; statement:  Replace the code in the CMainFrame::CMainFrame function with the following code: setlocale( LC_ALL, &quot;Japanese&quot; ); COleDateTime localtime(2004,1,1,1,1,1); MessageBox(localtime.Format(_T(&quot;%A, %B %d, %Y&quot;)),&quot;Date&quot;,MB_OK); </li> Press F7 to build the project.</li> Press Ctrl+F5 to run the project.</li></ol>
 * 1) include &quot;locale.h&quot; </li>

Result
A dialog box appears that contains the following:

, 1 01, 2004

Note  is a placeholder for a Japanese character.

Expected result
A dialog box appears that contains the following:

, 1 01, 16

Note  is a placeholder for a Japanese character.

<div class="references_section">