Skip to content

Instantly share code, notes, and snippets.

@alexandrebl
Created July 9, 2020 12:00
Show Gist options
  • Select an option

  • Save alexandrebl/2e61ec0f3fb735e17b04af36f3c43de0 to your computer and use it in GitHub Desktop.

Select an option

Save alexandrebl/2e61ec0f3fb735e17b04af36f3c43de0 to your computer and use it in GitHub Desktop.
Get TimeZone Brazil CSharp
public static class TimeZoneBrazil
{
public static DateTime GetCurrentLocalDate()
{
long ticks;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
ticks = TimeZoneInfo
.FindSystemTimeZoneById("America/Sao_Paulo")
.GetUtcOffset(DateTime.UtcNow).Ticks;
}
else
{
ticks = TimeZoneInfo
.FindSystemTimeZoneById("E. South America Standard Time")
.GetUtcOffset(DateTime.UtcNow).Ticks;
}
var currentLocalDate = new DateTime(ticks);
return currentLocalDate;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment