将WMI中的DateTime类型转换成VBS时间的函数代码
程序员文章站
2022-04-10 08:10:57
有两种方法可以转换,一种是自己写个函数解析: 复制代码 代码如下: function wmidatestringtodate(datetime) wmidatestring...
有两种方法可以转换,一种是自己写个函数解析:
function wmidatestringtodate(datetime)
wmidatestringtodate = _
cdate(mid(datetime, 5, 2) &_
"/" &_
mid(datetime, 7, 2) &_
"/" &_
left(datetime, 4) &_
" " &_
mid (datetime, 9, 2) &_
":" &_
mid(datetime, 11, 2) &_
":" &_
mid(datetime, 13, 2))
end function
另一种是使用swbemdatetime对象
function wmidatestringtodate(datetime)
set wbemdatetime = _
createobject("wbemscripting.swbemdatetime")
wbemdatetime.value = datetime
wmidatestringtodate = wbemdatetime.getvardate()
end function
复制代码 代码如下:
function wmidatestringtodate(datetime)
wmidatestringtodate = _
cdate(mid(datetime, 5, 2) &_
"/" &_
mid(datetime, 7, 2) &_
"/" &_
left(datetime, 4) &_
" " &_
mid (datetime, 9, 2) &_
":" &_
mid(datetime, 11, 2) &_
":" &_
mid(datetime, 13, 2))
end function
另一种是使用swbemdatetime对象
复制代码 代码如下:
function wmidatestringtodate(datetime)
set wbemdatetime = _
createobject("wbemscripting.swbemdatetime")
wbemdatetime.value = datetime
wmidatestringtodate = wbemdatetime.getvardate()
end function
参考链接:it's about time (oh, and about dates, too)
原文:http://demon.tw/programming/wmi-datetime-vbs.html