Set time zone for the entire project

2

I recently hosted an application on a North American server, so the dates are outside the Brazilian timezone. This way, I would like to know if there is a way to set the time zone only once so that every time you use DateTime.Now in a variable, its value is already updated according to the defined time zone.

Also, I would like to know if it is possible to define the Brazilian format once for all dates, without having to change the format for each variable.

    
asked by anonymous 18.07.2016 / 15:05

1 answer

1

Not possible. I do not even know if it's desirable. Schedules usually work best as UTC in most situations and are only displayed or handled in specific situations like timezone .

What you can do to make it a bit easier is to create a utility class with methods (possibly extension) that already give you the times in the timezone you want (you would keep in this utility class a static property indicating which is the timezone that you want and the methods would respect this without having to pass an argument telling you which one to use, even though you might optionally have a parameter to choose one other than the active pattern.

The presentation of the dates, not the spindle, can be done according to the culture configuration. There are some ways. By code it is used:

Thread.CurrentThread.CurrentCulture = new CultureInfo("pt-BR");
    
18.07.2016 / 15:14