Datetime.Now Does Not Update If Time Changes

Asked

Viewed 200 times

0

I have on application with a running timer, taking a 1000ms interval. This timer does some routines every X time, and among these routines the customer’s time is very important. we have already noticed that in some cases the time of the client that appears in the clock at the corner of the screen is right, but in the application comes with one hour less because the time zone of it is wrong.

After making the adjustments to the customer’s S.O. my application still captures the wrong date/time (with the wrong time zone).

line of code I’m using:

 Dim horariostatus As String = Format(System.DateTime.Now, "yyyy-MM-dd")
 horariostatus &= " " & Format(System.DateTime.UtcNow, "HH:mm:ss")

NOTE: Yes, I am storing in a String for later this information has some negotiations before sending to our server;

  • your application is executed on the client?

  • @Ricardopunctual yes, the application runs on the client;

1 answer

-1

 Dim current As TimeZoneInfo = TimeZoneInfo.Local //Pega Time Zone do Local da Execução do programa
 Dim horaDestino As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time") //Selecionamos a região da data e hora que desejamos gravar
 Dim horaAtual As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(current.Id) //Selecona o Time Zone para fazer a alteração
 Dim horaConvertida as DateTime //Variável que vai receber a data e a hora convertida

 horaConvertida = TimeZoneInfo.ConvertTime(Now, horaAtual, horaDestino) //Converte para o horário do servidor aqui no caso como horário de Brasília

Browser other questions tagged

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