zoukankan      html  css  js  c++  java
  • 时间格式转换

    在WMI中使用Win32_NTLogEvent查询出来的日志生成时间timegenerated类似于“20130820162350.350000+480“,这种时间格式很特殊,经查是DMTF时间格式字符串,在PowerShell中与其它时间类型进行比较就需要对其进行转换,将DMTF字符串转DateTime类型。

    转换的方案有两种:
     
    1)采用.NET 2.0中的System.Management.ManagementDateTimeConverter类
    该类位于system.management.dll动态链接库中,使用时需要先加载,代码如下:
    [void][Reflection.Assembly]::LoadFile("c:windowsmicrosoft.netframeworkv2.0.50727system.management.dll")
    gwmi win32_ntlogevent -Filter "logfile='application' and sourcename='db2' " -Property timegenerated,message -com $ip|
    select Message,@{Name="LogTime";Expression={[System.Management.ManagementDateTimeConverter]::ToDateTime($_.Timegenerated)}}|
    sort LogTime -desc
     
    2)使用事件对象的扩展方法 ConvertToDateTime
    gwmi -q "SELECT timegenerated FROM win32_ntlogevent WHERE logfile='application' and sourcename='db2'"|%{$_.ConvertToDateTime($_.Timegenerated)}
  • 相关阅读:
    【刷题-LeetCode】165 Compare Version Numbers
    python 22 内置模块2
    python 21 内置模块
    python 20 模块,包,及开发目录规范
    python 19
    python 18 三元,生成,递推
    定时抓取数据并存入数据库
    抓取财报数据
    金币
    交换座位
  • 原文地址:https://www.cnblogs.com/IvanChen/p/4492358.html
Copyright © 2011-2022 走看看