Conversion from a local client time system to CST and vice versa

I need to save the date-time in the CST time zone, regardless of any given time interval.

Clients who access the application are sent from different time zones, such as IST, CST, EST, ...

I need to save all the datetime entered by the client in the CST time zone to my database. And upon receipt, I need to convert the local time zone there.

How to do it?

+3
source share
2 answers

It is usually customary to store all datetime values ​​in your database in GMT / UTC format.

, UTC , , wilpeck, :

  • , UTC
  • UTC

EDIT:

:

StartDateTime, StartDateTimeOffset. " " (IST), 2009/10/13 14:45, 2009/10/13 09:15 UTC. , UTC (2009/10/13 09:15) StartDateTime +05: 30 StartDateTimeOffset. , , , UTC (2009/10/13 09:15) 2009/10/13 14:45.

+2

- , , . , , , . .NET 3.5 +

DateTime clientDateTime = DateTime.Now;
        DateTime centralDateTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(clientDateTime, "Central Time (US & Canada)");

EDIT:

DateTime UTC, , , . .

+2

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


All Articles