nodatime / nodatime

A better date and time API for .NET

Home Page:https://nodatime.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get PST time not PDT in standard way?

wujun4code opened this issue · comments

Pacific Daylight Time (PDT) is a North American time zone in use from the second Sunday in March to the first Sunday in November during Daylight Saving Time (DST). Pacific Standard Time (PST) is used during the remainder of the year.

PDT use winter or summer time but PST always use GMT -8.

Which timezone should I choose to get PST not PDT from the following TimeZone list : https://nodatime.org/TimeZones?

Thanks.

What you're looking for isn't really a regular time zone as such (neither PST nor PDT are time zones really - they're aspects which are observed in certain time zones). There are three options here:

  • Create a time zone using DateTimeZone.ForOffset
  • Use an ID = "UTC-08" with any IDateTimeZoneProvider
  • Use an ID of "Etc/GMT+8" with DateTimeZoneProviders.Tzdb - I'd advise against this, given that the Etc offsets are effectively the wrong way round

Sample code:

var zone1 = DateTimeZone.ForOffset(Offset.FromHours(-8));
var zone2 = DateTimeZoneProviders.Tzdb["UTC-08"];
var zone3 = DateTimeZoneProviders.Tzdb["Etc/GMT+8"];