【问题标题】:Convert WMI UTC time to unix time stamp using PHP使用 PHP 将 WMI UTC 时间转换为 unix 时间戳
【发布时间】:2013-06-12 15:05:33
【问题描述】:

我正在使用 PHP 对网络中的远程计算机进行 WMI 查询。

我正在使用这个获取 LastBootupTime 值:

$wmi_operatingsystem = $obj->ExecQuery("Select * from Win32_OperatingSystem"); 
$lastreboot = $wmi_call->LastBootupTime;

我的问题是 $lastreboot 类似于 20130612032422.112393-360。我需要将此值转换为 unix 时间戳或人类友好的东西。根据我的阅读,我相信这是 UTC 格式的时间戳。我试过使用 strtotime,但这对我不起作用。

帮助!

【问题讨论】:

    标签: php time wmi utc


    【解决方案1】:

    您可以使用SWbemDateTime 对象来解码 UTC 格式。

     $wtime = new COM ("WbemScripting.SWbemDateTime");  
     $wtime->Value = $wmi_call->LastBootupTime;
     //Now you can access the elements of the datetime using the SWbemDateTime properties  
     //like so $wtime->Year,$wtime->Month,$wtime->Day
    

    【讨论】:

    • 你能给我看一个使用上面 $lastreboot 变量的例子吗?谢谢! @RRUZ
    • @DobotJr,尝试HoursMinutes 属性,所有这些都在文档msdn.microsoft.com/en-us/library/windows/desktop/… 中。也不要忘记接受答案。
    • @ruzz,如果我能再打扰你一次。我已阅读您提供的链接中的文档,但找不到如何获取 AM 或 PM。有什么想法吗?
    • AFAIK Hours 属性返回一个介于 0 和 23 之间的值,因此您可以检查此属性的值以确定是 AM 还是 PM
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-29
    • 2015-09-08
    • 1970-01-01
    相关资源
    最近更新 更多