Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datetime timezone adjustments

Tags:

date

c#

My database is located in e.g. california. My user table has all the user's timezone e.g. -0700 UTC

How can I adjust the time from my database server whenever I display a date to the user who lives in e.g. new york? UTC/GMT -4 hours

like image 493
public static Avatar asked Sep 23 '08 00:09

public static


1 Answers

You should store your data in UTC format and showing it in local timezone format.

DateTime.ToUniversalTime() -> server;
DateTime.ToLocalTime() -> client

You can adjust date/time using AddXXX methods group, but it can be error prone. .NET has support for time zones in System.TimeZoneInfo class.

like image 59
aku Avatar answered Oct 10 '22 10:10

aku