Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Let say for example that your user is in New York (GMT - 5) and your server is in India (GMT + 5:30).</p> <p>When the user sees a "local" time of 10:00am (EST), your server would see a "local" time of 7:30pm (IST). However, by using UTC in both places....the user would see a UTC time of 3pm and the server would see a UTC time of 3pm.</p> <p>Using UTC in all places but keeping a referece of the users time zone allows you to always be working in UTC but still convert the times into the users "local" time when you want to show it to them.</p> <p>You also cannot rely on where a server is hosted especically if it is a virtual server. Nor can you assume what time zone the hosting company set their servers to. Best to always code defensivly by using <code>DateTime.UtcNow</code> when storing date times in the database.</p> <p>To convert this UTC time back to the time zone of a user you will need to do the following:</p> <pre><code>DateTime utcTime = new DateTime(2013, 03, 25, 10, 20, 00); TimeZoneInfo usersTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); DateTime usersLocalTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, usersTimeZone); Console.WriteLine(utcTime.ToString("hh:mm:ss"); Console.WriteLine(usersLocalTime.ToString("hh:mm:ss"); </code></pre> <p>FYI, you can find a list of the timezones from:</p> <pre><code>TimeZoneInfo.GetSystemTimeZones() </code></pre> <p>This should print out:</p> <pre><code>10:20:00 05:20:00 </code></pre> <p>As you can see, you will need to know the users time zone. There are 2 ways to know the users time:</p> <ol> <li>Have the user select their timezone in their user preferences</li> <li>Use some javascript to detect the timezone of their machine and post it back with the form</li> </ol> <p>I would suggest the first option there as the second one can make things more difficult for people. For example, if they are UK based and fly to the states for the week. Everything will change zones and they may not realise!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload