Skip to content Skip to sidebar Skip to footer

Save Datetime Issue With Users Local Datetime

I built something like chat service in a website, and when a user send a message or receive a message I show for him when the message sent or received. I save all messages in the D

Solution 1:

If the timestamp is stored as Coordinated Universal Time (UTC), then all you should have to is format the value from the database according to the user's local timezone.

For example, assuming that the timestamp from the database is in milliseconds (e.g. 1309365893296), then in javascript, you can do the following to convert it to the user's local timezone:

var localtime = newDate(1309365893296);

Solution 2:

I'd guess the best way would be to collect a DateTime value from your user's PC whenever they submit text.

From that, you should be able to determine what time zone they are in based on the number of hours difference.

Then, whenever you display the time stamp in your application, add or subtract the number of hours difference.

Solution 3:

What you need to do is store all of your timestamps using DateTime.UtcNow

When you go to display the time to the user, you can use .ToLocalTime() off of your variable to convert it to each users' local timezone.

Post a Comment for "Save Datetime Issue With Users Local Datetime"