Current time in Brazil C #

0

I'm trying to get the current time of states / DF Brazil with different time. I found the code below but it did not help much. Does anyone know of any way to do without webservice ?

public static void Main()
{
    DateTime timeUtc = DateTime.UtcNow;
    var kstZone = TimeZoneInfo.FindSystemTimeZoneById("E. South America Standard Time");
    var horaBrasilia= TimeZoneInfo.ConvertTimeFromUtc(timeUtc, kstZone);
    Console.WriteLine(String.Format("Hora Brasilia: {0}",horaBrasilia));
    //Console.WriteLine(String.Format("Hora Amazonas: {0}",horaAmazonas));
    //Console.WriteLine(String.Format("Hora Acre: {0}",horaAcre));
    //Console.WriteLine(String.Format("Hora Piaui: {0}",horaPiaui));
}
    
asked by anonymous 20.11.2016 / 00:48

1 answer

3

The territorial extension of Brazil comprises 4 time zones (-2hs, -3hs, -4hs and -5hs in relation to Greenwich). You can get the time on each of these spindles through the following code:

        Console.WriteLine ("Exibir horários conforme TimeZone");
        DateTime timeUtc = DateTime.UtcNow;
        var noronha = TimeZoneInfo.FindSystemTimeZoneById("Brazil/DeNoronha");
        var brasilia = TimeZoneInfo.FindSystemTimeZoneById("Brazil/East");
        var amazonas = TimeZoneInfo.FindSystemTimeZoneById("Brazil/West");
        var acre = TimeZoneInfo.FindSystemTimeZoneById("Brazil/Acre");

        Console.WriteLine(String.Format("UTC Time: {0}",timeUtc.ToString()));
        Console.WriteLine(String.Format("Hora Noronha: {0}",TimeZoneInfo.ConvertTimeFromUtc(timeUtc, noronha).ToString()));
        Console.WriteLine(String.Format("Hora Brasilia: {0}",TimeZoneInfo.ConvertTimeFromUtc(timeUtc, brasilia).ToString()));
        Console.WriteLine(String.Format("Hora Amazonas: {0}",TimeZoneInfo.ConvertTimeFromUtc(timeUtc, amazonas).ToString()));
        Console.WriteLine(String.Format("Hora Acre: {0}",TimeZoneInfo.ConvertTimeFromUtc(timeUtc, acre).ToString()));

However, this does not match the response according to each region of the country. For example, the North region has part of its territory with -5hs (Acre), -4hs (Amazonas, Rondônia and Roraima) and -3hs (Pará, Amapá and Tocantins) in relation to Greenwich. The Central-West region, with the exception of Goiás (-3hs) is framed in the -4hs spindle. The rest of Brazil (Northeast, Southeast and South) has the -3hs spindle. The exception is Noronha which has -2hs compared to Greenwich.

It should be noted that during the summer time the Northeast, Southeast and South regions have the same spur of Noronha (-2hs).

    
20.11.2016 / 02:28