ASP.NET Application and Local Time Zone

I have an ASP.NET application that is located in time zone A and used by users in time zone B. Is there a way to set the time zone of the entire web application to B, even if the hosting environment is in A? I already set the globalization tag in web.config with the corresponding uiCulture and culture values, and they work fine for the days of the week and other localization parameters, unfortunately, they did not adjust the clock: / What is the easiest thing I can do to complete the setup, therefore when I use DataTime.Now in the application, I get the current time in the time zone B is not A. thanks.

+3
source share
3 answers

Assuming that you have permission to make this change: Set the time zone of the machine to B, I will suggest that all users of the application use the same time zone.

Otherwise: Store Utc timezone offset B and use this combination, although this can lead to daylight saving time problems, maybe.

+3
source

Get the client’s time zone offset from UTC in minutes via a JavaScript Date.getTimezoneOffset () call and pass this back to the server via a hidden input field.

Serverside uses DateTime.UTCNow to get the server time in UTC.

Serverside uses DateTime.SpecifyKind to convert between local server time and UTC as needed.

+3
source

-, . UTC , ( ).

.

I agreed that this is a terrible way of programming, and not at all easy or effective, but for me it is the only way.

0
source

Source: https://habr.com/ru/post/1708766/


All Articles