Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

248
Visualizações
How to find future UTC offset based on specific date and time zone name using Angular?

Is there an equivalent for figuring out UTC offset by supplying date, time, time zone name using Angular? This is very easy in C# - example below:

TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("US Eastern Standard Time");

string dateInput = "2022-11-15";
var parsedDate = DateTime.Parse(dateInput);
TimeSpan offset = tzi.GetUtcOffset(parsedDate); // this returns -5

string dateInput2 = "2022-03-20";
var parsedDate2 = DateTime.Parse(dateInput2);
TimeSpan offset2 = tzi.GetUtcOffset(parsedDate2); // this returns -4
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The JavaScript getTimezoneOffset() method is used to find the timezone offset

let d = new Date(Date.parse("2022-03-21T06:38:30+0000"));
console.log(d.getTimezoneOffset()) // 120 minutes offset for me

about 4 years ago · Juan Pablo Isaza Relatório

0

After many hours spent on this I decided to give moment.js as suggested by Joosep.P to try some library and also by others. The below seems to work as expected. What is bizarre is if you try to use timezoneName other than where you currently are and if you debug, you will still see your own time zone name for the date, however the offset will be calculated correctly. I assume that this works because of proper setting .tz call.

var timezoneName = 'America/New_York';
var dateInput = '2022-11-15';
var parsedDate = moment.tz(dateInput, timezoneName);
var offseta = parsedDate.utcOffset()/60; // this returns -5
var offsetb = moment.tz(dateInput, timezoneName).format('Z'); // returns '-05:00' as a string

var dateInput2 = '2022-03-20';
var parsedDate2 = moment.tz(dateInput2, timezoneName);
var offset2a = parsedDate2.utcOffset()/60; // this returns -4
var offset2b = moment.tz(dateInput2, timezoneName).format('Z'); // returns '-04:00' as a string
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda