Time format Conversion

Source: Internet
Author: User

Log generation time using Win32_NTLogEvent query in WMI timegenerated similar to "20130820162350.350000+480", this time format is very special, is the DMTF time format string, Comparisons with other time types in PowerShell require conversion and the DMTF string to a datetime type.

There are two scenarios for conversion: 1) using. NET The System.Management.ManagementDateTimeConverter class in 2.0 is located in the System.management.dll Dynamic link library, which needs to be loaded first, with the following code: [void][ Reflection.assembly]::loadfile ("C:\windows\microsoft.net\framework\v2.0.50727\system.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) Use the extension method of the Event object Converttodatetimegwmi-q "select TimeGenerated from Win32_NTLogEvent WHERE logfile= ' application ' and sourcename= ' DB2 ' "|%{$_. Converttodatetime ($_. timegenerated)}

Time format Conversion

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.