时间转换

cppfaq 2014-05-09 09:21:00
请教,对于一个const char * 包含的wmi datetime(UTC)比如:
20140506032713.000000+***

如何能够转成FILETIME类型。
...全文
140 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2014-05-09
  • 打赏
  • 举报
回复
當系統在內部使用通用協調時間或 UTC 為基礎的時間時,應用程式,通常會顯示當地時間或日期與您的時區的時間。不過,開發人員有時候可能需要以程式設計方式將 (先前稱為格林威治標準時間或 GMT) 的 UTC 時間轉換為本地時間。 使用下列的 Win32 函式,就可以完成這項轉換: // Converting UTCTime to LocalTime. FILETIME FileTime, LocalFileTime; SYSTEMTIME UTCTime, LocalTime; SystemTimeToFileTime(&UTCTIme,&FileTime); FileTimeToLocalFileTime(&FileTime, &LocalFileTime); FileTimeToSystemTime(&LocalFileTime, &LocalTime);
赵4老师 2014-05-09
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <string.h>
#include <time.h>
struct tm st;
time_t tt;
char timstr[40];
char tmpbuf[128];
char c;
int t;
int AP() {
    if ('P'==c || 'p'==c) {st.tm_hour+=12;return 1;}
    if ('A'==c || 'a'==c)                 return 1;
                                          return 0;
}
int dtparse() {
    if (7==sscanf(timstr,"%d/%d/%4d %d:%d:%d %c",&st.tm_mday,&st.tm_mon ,&st.tm_year,&st.tm_hour,&st.tm_min,&st.tm_sec,&c)) if (AP()) goto STEP2;
    if (6==sscanf(timstr,"%d/%d/%4d %d:%d%c"    ,&st.tm_mday,&st.tm_mon ,&st.tm_year,&st.tm_hour,&st.tm_min           ,&c)) if (AP()) goto STEP1;
    if (6==sscanf(timstr,"%4d/%d/%d %d:%d %c"   ,&st.tm_year,&st.tm_mon ,&st.tm_mday,&st.tm_hour,&st.tm_min           ,&c)) if (AP()) goto STEP1;
    if (5==sscanf(timstr,"%d.%d.%4d %d:%d"      ,&st.tm_mon ,&st.tm_mday,&st.tm_year,&st.tm_hour,&st.tm_min              ))           goto STEP1;
    if (6==sscanf(timstr,"%4d-%d-%d %d:%d:%d"   ,&st.tm_year,&st.tm_mon ,&st.tm_mday,&st.tm_hour,&st.tm_min,&st.tm_sec   ))           goto STEP2;
STEP1:
    st.tm_sec=0;
STEP2:
    st.tm_year-=1900;
    if (st.tm_mon>12) {t=st.tm_mon;st.tm_mon=st.tm_mday;st.tm_mday=t;}
    st.tm_mon-=1;
    tt=mktime(&st);
    if (-1!=tt) {
        strftime(tmpbuf,128,"%Y-%m-%d %H:%M:%S",localtime(&tt));
        return 1;
    } else {
        printf("[%s] is Invalid time string!\n",timstr);
        return 0;
    }
}
int main() {
    strcpy(timstr,"10.01.2012 15:43"        );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);
    strcpy(timstr,"8/11/2006 11:10AM"       );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);
    strcpy(timstr,"2006/10/31 04:50 PM"     );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);
    strcpy(timstr,"1/6/2010 5:20:12 PM"     );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);
    strcpy(timstr,"13/12/2012 11:16:17 a.m.");if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);
    strcpy(timstr,"2013-06-08 09:56:59"     );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);
    return 0;
}
//[10.01.2012 15:43] is [2012-10-01 15:43:00]
//[8/11/2006 11:10AM] is [2006-11-08 11:10:00]
//[2006/10/31 04:50 PM] is [2006-10-31 16:50:00]
//[1/6/2010 5:20:12 PM] is [2010-06-01 17:20:12]
//[13/12/2012 11:16:17 a.m.] is [2012-12-13 11:16:17]
//[2013-06-08 09:56:59] is [2013-06-08 09:56:59]
//
Time Functions The following functions are used with time. CompareFileTime DosDateTimeToFileTime FileTimeToDosDateTime FileTimeToLocalFileTime FileTimeToSystemTime GetFileTime GetLocalTime GetSystemTime GetSystemTimeAdjustment GetSystemTimeAsFileTime GetTickCount GetTimeZoneInformation LocalFileTimeToFileTime SetFileTime SetLocalTime SetSystemTime SetSystemTimeAdjustment SetTimeZoneInformation SystemTimeToFileTime SystemTimeToTzSpecificLocalTime Obsolete Functions GetCurrentTime

65,187

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧