簡體   English   中英

使用用戶的“區域和語言”格式將Windows SYSTEMTIME轉換為C ++中的字符串或char buf?

[英]convert Windows SYSTEMTIME to a string or char buf in C++ with user's “Region and Language” format?

我的C ++程序如何將用戶首選的“長日期格式”中的SYSTEMTIME轉換為默認語言設置,或者在控制面板 - >區域和語言對話框中自定義設置?

如果重要的是我在Visual Studio 2017上主要尋找C / C ++ 03類型的解決方案,但如果有新的C ++解決方案,我不介意看到它。

TCHAR buf[200];
GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &mysystime, NULL, buf, 200);

如果您還需要時間部分,也可以調用GetTimeFormat

TIME_ZONE_INFORMATION tzi;
if ( GetTimeZoneInformation( &tzi ) == TIME_ZONE_ID_INVALID )
MyErrorFunction( "GetTimeZoneInformation() = TIME_ZONE_ID_INVALID : %s",
    GetLastErrorAsString().c_str() );
  :
  :

SYSTEMTIME st, stLocal;
BOOL bRV = FileTimeToSystemTime( ftLastAccessTime, &st );
SystemTimeToTzSpecificLocalTime( &tzi, &st, &stLocal );

GetDateFormat( LOCALE_USER_DEFAULT, DATE_LONGDATE, &stLocal,
               NULL, szBuf, sizeof( szBuf ) );

int iBufUsed = strlen( szBuf );
if ( iBufUsed < sizeof( szBuf ) - 2 )
     szBuf[ iBufUsed++ ] = ' ';

GetTimeFormat( LOCALE_USER_DEFAULT, 0, &stLocal,
               NULL, szBuf + iBufUsed, sizeof( szBuf ) - iBufUsed );

// szBuf holds Date and Time, in the user's timezone, formatted as the user prefers.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM