[英]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.