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.

Local : The time represented is local time.

UTC : The time represented is UTC.

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.