当我使用Variant时,Vc ++为日期输出错误的输出 [英] Vc++ Give Wrong Output For Date When I Use It With Variant

查看:105
本文介绍了当我使用Variant时,Vc ++为日期输出错误的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Win32_NTLogEvent的程序。当我在其中使用时间生成的属性时。它运行但输出错误..



我的代码如下



 hres = pclsObj-> Get(L   TimeWritten 0 ,& vtProp, 0  0 ); 
wcout<< 写入事件日志时间:<< vtProp.date<< endl<<结束

hres = pclsObj-> Get(L TimeGenerated,< span class =code-digit> 0 ,& vtProp1, 0 0 );
wcout<< 生成事件日志时间:<< vtProp1.date<< endl<<结束



我的输出为



事件记录时间-9.25596e + 061



生成的事件日志时间-9.25596e + 061



不是日期/时间格式

解决方案

这会返回一个CIM日期时间BSTR字符串(CIM_DATETIME)。



http://msdn.microsoft.com/en-us/library/aa387237(v=vs.85)。 aspx [ ^ ]



http: //technet.microsoft.com/en-us/library/ee156576.aspx [ ^ ]



它可能会以这种方式转换:

http://blogs.msdn.com/b/oldnewthing/archive/2012/11/02/10365035.aspx [ ^ ]



http://myitforum.com/myitforumwp/2012/08/01/converting -tofrom-wmi-date-time / [ ^ ]



在C#中你可以使用ManagementDateTimeConverter.ToDateTime。



我已经发布了关于如何巧妙地做到这一点的提示如何解码使用C ++的WMI查询中使用的CIM_DATETIME格式 [ ^ ]

hi i ma wittting program for Win32_NTLogEvent..when i use time generated property in it. it runs but gives me wrong output..

My code is as below

    hres = pclsObj->Get(L"TimeWritten", 0, &vtProp, 0, 0);
    wcout << "Event Log time written : " << vtProp.date << endl << endl ;

hres = pclsObj->Get(L"TimeGenerated", 0, &vtProp1, 0, 0);
    wcout << "Event Log time generated : " << vtProp1.date << endl << endl ;


and i got output as

Event Log time written -9.25596e+061

Event Log time generated -9.25596e+061

which is not in date/time format

解决方案

This returns a CIM datetime BSTR string (CIM_DATETIME).

http://msdn.microsoft.com/en-us/library/aa387237(v=vs.85).aspx[^]

http://technet.microsoft.com/en-us/library/ee156576.aspx[^]

It may be converted in this way:
http://blogs.msdn.com/b/oldnewthing/archive/2012/11/02/10365035.aspx[^]

http://myitforum.com/myitforumwp/2012/08/01/converting-tofrom-wmi-date-time/[^]

In C# you can use ManagementDateTimeConverter.ToDateTime.

[Edit] I have posted a tip on how to do this neatly How to decode the CIM_DATETIME format employed in WMI queries using C++[^]


这篇关于当我使用Variant时,Vc ++为日期输出错误的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆