Question with formatted time return asp.net mvc

1

In the application I have a query that compares the current time of the server with a pre-set timetable recorded in a table:

select  CAST(HORA_FECHAMENTO AS datetime) as HORA_FECHAMENTO, 
 CAST(CONVERT(VARCHAR(11),GETDATE(),8) as datetime) as HORA_ATUAL 
 from TB_ESTRACAO  
 where IDEXTRACAO = 1 

When I send this information to the screen I am formatting it as follows:

Session["hora_atual_servidor"] = String.Format("{0:T}", retornoHoraAtual.HORA_ATUAL);
Session["hora_final_valida"] = String.Format("{0:T}", retornoHoraAtual.HORA_FECHAMENTO);

The application running on the local machine shows me the information:

Ontheserver,theinformationlookslikethis:

To complete the server returns me the wrong time with a difference of almost 40 minutes unless the current time is when it is 10:00 PM shows as 10:00 PM, how could I solve this problem?

    
asked by anonymous 11.01.2016 / 04:54

1 answer

2

This problem is because of Globalization, you have two options to resolve this, change the CultureInfo that your application is running, then it will change for all calls, ie you should realize that the thousand separator is ',' and the decimal separator is '.', because the culture should be running in English.

To change to the entire application, you can change it in web.config, as per the link link

Or change only the formatting of this return, as shown below:

 string.Format(System.Globalization.CultureInfo.GetCultureInfo("pt-BR"), "{0:T}", DateTime.Now)

On the 40-minute difference, the server where your database is located must be in another TimeZone.

You can retrieve local time based on Brasilia, as follows:

Session["hora_atual_servidor"] = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("E. South America Standard Time")); //"E. South America Standard Time" é Brasília

I hope I have helped.

    
11.01.2016 / 14:58