SYSTEMTIME 转化为 tm struct 并根据本地的设置输出
2015-04-13 15:17
85 查看
{
// 0. variable definition
SYSTEMTIME Reg_systime; // System time from regist
_locale_t locale = NULL; // local to determine time show style
struct tm Reg_showtime; // Reg show time from System time
// 1. Init Reg_systime
ZeroMemory(&Reg_systime, 0, sizeof(SYSTEMTIME));
DWORD dwTimeLen = sizeof(SYSTEMTIME);
// 2. Read system time from reg
GetSystemTime(&Reg_systime);
// 3. Get Reg_showtime from Reg_systime
// month and year need to modify, others are the same
Reg_showtime.tm_sec = Reg_systime.wSecond; // Second
Reg_showtime.tm_min = Reg_systime.wMinute; // Minute
Reg_showtime.tm_hour = Reg_systime.wHour; // Hour
Reg_showtime.tm_mday = Reg_systime.wDay; // Day
Reg_showtime.tm_mon = Reg_systime.wMonth -1; // Month
Reg_showtime.tm_year = Reg_systime.wYear - 1900; // Year
Reg_showtime.tm_wday = Reg_systime.wDayOfWeek; // Day of week
// 4. Get the implementation-defined native environment
locale = _create_locale(LC_ALL,"");
if (locale == NULL)
{
OutputDebugString(TEXT("_create_locale() failed\r\n"));
return FALSE;
}
// 5. Set ptszTimeBuf value
_tcsftime_l(ptszTimeBuf, dwBufLen, ptszTimeFormatCtrl, &Reg_showtime, locale);
if (locale)
{
_free_locale(locale);
}
return TURE;
}
用法:
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR *ptszTimeFormat = TEXT("%#c"); //TEXT("%c")
TCHAR tszTimeBuf[100] = {0};
BOOL bres = GetTimeFromInf(ptszTimeFormat, tszTimeBuf, 100);
if (!bres)
{
OutputDebugString(TEXT("GetTimeFromRegist failed !\r\n"));
return 0;
}
TCHAR tszDebugMsg[100] ={0};
_stprintf_s(tszDebugMsg, 100, TEXT("%s Format UTC Time is %s\r\n"), ptszTimeFormat, tszTimeBuf);
MessageBox(NULL, tszDebugMsg, TEXT("test"), MB_OK);
}
相关文章推荐
- 用python+selenium从百度获取本地明日的天气信息并根据温度情况设置提醒
- Win8本地IP地址根据路由器情况完美设置方案
- SimpleDraweeView根据本地路径或Uri设置图片,动态改变宽高
- NSDate存储的是世界标准时(UTC),输出时需要根据时区转换为本地时间
- NSDate存储的是世界标准时(UTC),输出时需要根据时区转换为本地时间
- strftime()函数根据区域设置格式化本地时间/日期 setlocale() 函数设置地区信息(地域信息)
- smarty date_format 根据本地环境输出星期几的乱码问题
- USTC机试—根据输入的十进制数字转化成二进制数字输出的同时,输出2进制数字中1的个数
- 根据需要为不同的类设置不同的输出日志名称及日志格式
- strftime() 函数根据区域设置格式化本地时间/日期
- 根据输出设置select的被选中值
- android下eclipse中的Logcat 查看system.out.print()输出设置
- lua 根据图片高度设置scrollview高度
- 加载数据后,根据列值设置不同的行颜色
- c++设置控制台输出的行数和列数
- 取消c++所设置的cout中setprecision输出的格式
- C#word(2007)操作类--新建文档、添加页眉页脚、设置格式、添加文本和超链接、添加图片、表格处理、文档格式转化
- Javascript:根据用户输入的数字输出成语
- 根据应用程序设置JVM参数(一)-设置堆、新生代、老年代、持久代大小
- 根据用户需要输出打印菱形,用for循环输出打印星号组成的菱形