PowerShell: Find if time variable is in UTC or local time

综合技术 2016-04-09

How do we know if a variable of type [DateTime] is in UTC or Local time zone? Let us see how to achieve this using PowerShell.

First you need to ensure that date time information is stored in proper DateTime variable. To check you can invoke GetType() method on the variable that is containing the date time information and it tells us whether it is of date time type or not.

$Date = Get-Date

$Date . GetType()

Once it is confirmed then you can check if the time in the variable is a local time or in UTC timezone by reading the Kind property value. This property has 3 possible values.

  1. Local : The time represented is local time.
  2. UTC : The time represented is UTC.
  3. Unspecified : The time represented is not specified as either local time or Coordinated Universal Time (UTC).

Let us see a quick example:

$Date = Get-Date

$Date . Kind

$UTCDate = $Date . ToUniversalTime()

$UTCDate . kind

A sample screenshot of output is below:

Hope you liked it. Do you know how to find the exact time zone of a date time variable? I will come up with another post for it.

责编内容by:Techibee.com (源链)。感谢您的支持!


【技术分享】绕过LSASS的SACL审计 2017-10-30 10:07:19 阅读:336次 来源: tyranidslair.blogspot.co.uk ...
PowerShell Parameter Disambiguation and a Surprise When you’re learning PowerShell one of the first things you will notice is that...
Curly Blue and the meaning of scripting – Part 3 Summary: Curly Blue discovers the raw power of Cim-Instance combined with Power...
Installation Automated for PSSQLLib The last few weeks the amount of views on my blog exploded. Especially the page ...
内网渗透测试定位技术总结 0x01 前言 说起内网定位,无论针对内网查找资料还是针对特殊人物都是非常实用的一项技术。这里把目前能够利用的手段&工具都一一进行讲解。 ...