简体   繁体   中英

How to get daylight savings start and end for a time zone in Dynamics CRM?

In CRM Online 2013, I need to determine the start and end dates of daylight savings time based on a specific time zone. I have code that needs to display times converted for different time zones, aside from the time zone in the current user's settings. For example, if the current user's time zone is set to EST - Eastern Standard Time they will see date/time values in their local time, but I need to have a web resource on an entity form display that date/time converted to other time zones. I can get the standard offset for each time zone but can't find any accurate data that indicates the start month/day of daylight savings time so I know when to use that offset. Using the OData service endpoint I looked at TimeZoneDefinition and TimeZoneRule entities, and also at the user's current timezone in UserSettings entity. I checked the attributes on those entities but they have incorrect values for Daylight Savings month/day. For example, looking at EST time zone I see Daylight month and day of March 2nd, but it should be March 8.

I have verified that CRM itself works fine as expected, setting date/time values on a form result in the correct UTC value for standard time up through 3/7 and daylight savings time starting 3/8, but I need to access this same info from within a javascript web resource. Any help is much appreciated.

I think I just realized what the issue is. I was expecting the values to be defined as the specific month and day (as in day of the month) when daylight savings starts. I believe that the day value (DaylightDay or TimeZoneDaylightDay depending on what entity you're looking at) is part of the standard rule definition for Daylight Savings Time. A day value of 2 really means the second occurrence of that day in the month, and needs to be taken along with DaylightDayOfWeek value. For example, if the month is 3, day is 2, and day of week is 0, this would be read as the second(2) Sunday(0) in March(3). That makes sense now that I see it, this is just the rule that can be used to calculate the actual start of DST in any given year.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM