Timezone do Brasil para Datetimeoffset C#

Asked

Viewed 3,984 times

4

I’d like to know what’s possible Timezones available for all regions of Brazil.

I saw we got the E. South America Standard Time for Brasília’s time, but for example, what would be the Timezone acre?

  • Acre is America/Rio_Branco. See everything that has "BR" here: https://github.com/eggert/tz/blob/2018g/zone1970.tab#L85

  • In my case I’m using it as follows: Timezoneinfo.Findsystemtimezonebyid("E. South America Standard Time"); But with America/Rio_white it’s not right :(

  • Ah, it must be because C# uses Windows timezone names (and I don’t know if it has one specific for Acre), while America/Rio_Branco is listed by IANA - see the difference between them here: https://stackoverflow.com/tags/timezone/info (see the section "Time Zone Databases")

  • 2

    Thanks friend, I searched and using the Timezoneconverter framework to use the IANA list Timezones.

1 answer

3


I found in the documentation the method TimeZoneInfo.GetSystemTimeZones(), that:

Timezoneinfo.Getsystemtimezones Method

Returns a classified collection of all time zones for which information is available on the local system.

And in the documentation of the function TimeZoneInfo.FindSystemTimeZoneById(), that the author of the question is using, says the following:

Timezoneinfo.Findsystemtimezonebyid(String) Method

Retrieves an object TimeZoneInfo Registry based on your identifier.

On Windows systems, FindSystemTimeZoneById tries to match id for log branch Subkey names HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones.

I used the method:

// Retorna uma coleção do tipo
// System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo>.
var timeLista = TimeZoneInfo.GetSystemTimeZones();

I separated some of the returned items, and also analyzed these items in the Registry of Windows, in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones, and finally got to the following list:

+--------------------------------------------------+---------------------------------+---------------------------------+
|                   DisplayName                    |          StandardName           |          DaylightName           |
+--------------------------------------------------+---------------------------------+---------------------------------+
| (UTC-05:00) Bogota, Lima, Quito, Rio Branco      | SA Pacific Standard Time        | SA Pacific Daylight Time        |
| (UTC-04:00) Cuiaba                               | Central Brazilian Standard Time | Central Brazilian Daylight Time |
| (UTC-04:00) Georgetown, La Paz, Manaus, San Juan | SA Western Standard Time        | SA Western Daylight Time        |
| (UTC-03:00) Araguaina                            | Tocantins Standard Time         | Tocantins Daylight Time         |
| (UTC-03:00) Brasilia                             | E. South America Standard Time  | E. South America Daylight Time  |
| (UTC-03:00) Cayenne, Fortaleza                   | SA Eastern Standard Time        | SA Eastern Daylight Time        |
| (UTC-03:00) Salvador                             | Bahia Standard Time             | Bahia Daylight Time             |
+--------------------------------------------------+---------------------------------+---------------------------------+
  • 1

    I got it, I tested it with the mentioned timezones and it all worked out! Thanks Pedro :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.