Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Powershell get timezone with DST

In powershell I’m using

(Get-Timezone).BaseUtcOffset

to get the UTC offset of a computer which gives me +1h for my timezone. That is technically correct since I’m in CET in winter (UTC+1) and CEST in summer (UTC+2). Right now tho it is DST, so CEST (UTC+2) for me so I’m wondering how I could get this information in powershell since the above command tells me that my timezone is UTC+1 and doesn’t mention DST at all.

As a workaround I currently use

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$date = Get-Date
($date - $date.ToUniversalTime()).TotalMinutes

to get the offset from UTC of my timezone with DST. It evaluates to +120 minutes which is exactly what i need.

Output of Get-Timezone:

Id                         : W. Europe Standard Time
DisplayName                : (UTC+01:00) Amsterdam, Berlin, Bern, Rom, Stockholm, Wien
StandardName               : Mitteleuropäische Zeit
DaylightName               : Mitteleuropäische Sommerzeit
BaseUtcOffset              : 01:00:00
SupportsDaylightSavingTime : True

Output of $date – $date.ToUniversalTime():

Days              : 0
Hours             : 2
Minutes           : 0
Seconds           : 0
Milliseconds      : 0
Ticks             : 72000000000
TotalDays         : 0,0833333333333333
TotalHours        : 2
TotalMinutes      : 120
TotalSeconds      : 7200
TotalMilliseconds : 7200000

>Solution :

Yes, you can use the static method IsDaylightSavingTime on the TimeZoneInfo class to get this information from a desired DateTime:

$now = [DateTime]::Now
[System.TimeZoneInfo]::Local.IsDaylightSavingTime($now) # Returns $True or $False
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading