Home » How to Convert Date to UTCTime in PowerShell

How to Convert Date to UTCTime in PowerShell

To convert a date to Coordinated Universal Time (UTC) in PowerShell, you can use the ToUniversalTime() method.

The following method shows how you can do it.

Method 1: Convert date to UTCTime

$date = Get-Date

# Convert the DateTime object to UTC
$utcDateTime = $date.ToUniversalTime()

Write-Output $utcDateTime

This example will output the current date and time in Coordinated Universal Time (UTC).

The following example shows how to use this method.

Convert Date to UTCTime in PowerShell

The following syntax shows how you can do it.

$date = Get-Date

# Convert the DateTime object to UTC
$utcDateTime = $date.ToUniversalTime()

Write-Output $utcDateTime

Output:

PowerShell convert date to UTCTime
PowerShell convert date to UTCTime

In this script, we define the $date variable that stores the current date and time. We then use the ToUniversalTime() method to convert the current date and time to UTC Time and store it in the $utcDateTime variable

Finally, we output the current date and time in Coordinated Universal Time (UTC) using the Write-Output cmdlet.

Conclusion

I hope the above article on converting a date to UTCTime in PowerShell is helpful to you.

You can find more topics about Active Directory tools and PowerShell basics on the ActiveDirectoryTools home page.