Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set timezone within PowerShell Get-Date?

Is there a way to adjust the timezone within a Get-Date statement? I'm trying to run the following command within a PowerShell module and the date and time for the results it generates are all in PST, I'm trying to get everything into EST.

Start-Five9Report -FolderName [name] -ReportName [name] -EndDateTime (Get-Date).AddMinutes(-1) -StartDateTime (Get-Date).AddMinutes(-10)
like image 673
Navarro_refugee Avatar asked Feb 06 '26 12:02

Navarro_refugee


1 Answers

Yes, use the TimeZoneInfo.ConvertTimeBySystemTimeZoneId static method. This can be done on one line but I broke it up for readability:

[System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId(
  [DateTime]::Now,
  "Eastern Standard Time"
)

You can use ( Get-Date ) in place of [DateTime]::Now if you wish.


For the destinationTimeZoneId argument "Central Standard Time", you can get the correct Id to use for each time zone by running the TimeZoneInfo.GetSystemTimeZones static method:

[System.TimeZoneInfo]::GetSystemTimeZones()

and making note of the Id property value for the time zone you want. Note that each time zone is aware of whether it should follow Daylight Savings Time or Standard Time. You do not need to (nor will it work) provide an alternate Id for DST-enabled time zones.

like image 198
Bender the Greatest Avatar answered Feb 08 '26 04:02

Bender the Greatest



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!