DateTime From World Clock API

Just a tip #7

A simple REST API get method call to retrieve the datetime from service.

This script returns the current date time from using REST API service.
You can find the latest uri from the site above.
Eastern Standard Time
Coordinated Universal Time
Also supports JSONP
Central European Standard Time

# utc time url
[string] $WorldClockAPIUrl = ''

# Invoke Get method. The API returns the output in json format, but by default Invoke-RestMethod will convert from JSON to readable format (pacustomobject)
[psobject] $ApiResult = Invoke-RestMethod -Method Get -Uri $WorldClockAPIUrl

<# Selecting only current datetime from the api output
$id                   : 1
currentDateTime       : 2019-02-27T11:51Z
utcOffset             : 00:00:00
isDayLightSavingsTime : False
dayOfTheWeek          : Tuesday
timeZoneName          : UTC
currentFileTime       : 131957418910000000
ordinalDate           : 2019-58
serviceResponse       :
[string] $UTCTimeString = $ApiResult.currentDateTime

# Convert the string to datetime using .Net datetime class method Parse(), and returns datetime in default culture
[datetime]$DateTime =  [System.DateTime]::Parse($UTCTimeString)

# output datetime
return $DateTime

Share it on     |   |   |   | 

Run CmdLets Without Installing The Modules - Implicit Remoting


Windows Terminal and My Customization, it’s awesome.

comments powered by Disqus