Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# british summer time (BST) timezone abbreviation

Tags:

timezone

c#

.net

I need to display a label with the current time zone abbreviation. My pc's timezone is currently set to "(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London". As a result, I would like to see BST displayed, since LN is currently in british summer time.

It looks like that info (timezone abbrev) is not available. Looking at the GMT TimeZoneInfo, all I can see with regard to names is

Id  "GMT Standard Time"
StandardName    "GMT Standard Time"
DaylightName    "GMT Daylight Time"

Is there any way to get to BST from "GMT Daylight Time" or any other available Windows timezone info?

like image 574
Flack Avatar asked Apr 12 '12 14:04

Flack


2 Answers

The TimeZoneInfo class referrers to "British Summer Time" as "GMT Daylight Time", so no it is not possible. If Microsoft were to store it as "BST" it would be in the DaylightName property.

Whilst following the development of the TimeZoneInfo class on the BCL blog many years ago, I saw no explanation behind how they chose the values for DaylightName. If I were to guess it would be because this is for a "Time Zone" and not a particular city.

It appears that the public-domain tzdatabase, which is considered to be more complete than Microsoft's time zone database, does display BST for London (source). This is because Cities are included in this dataset, not just the Time Zones. There is a Project called Noda Time that brings the tzdatabase to .Net that is now avaialble.

like image 97
DaveShaw Avatar answered Oct 22 '22 22:10

DaveShaw


You should know that all the time zones that say "Standard" will properly switch to daylight time in the summer. For example TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time") will be an object that can properly handle both standard and daylight times. The same is true for, say, "Pacific Standard Time".

like image 24
ErikE Avatar answered Oct 22 '22 23:10

ErikE