0

Simple scenario:

John Doe lives in California and posts a comment. Jane Doe lives in Maryland and views the comment.

I'm used to dealing with local based websites and usually use GETDATE(). What's the best way to deal with this so that John and Jane see the date based on their time location? Do I send a parameter to the SQL query based on a javascript function to grab their timezone? Is there a better way?

A good example is Facebook. How do they deal with all the different time zones? Is it client side? server side? etc.

Thanks!

user1447679
  • 3,076
  • 7
  • 32
  • 69
  • GMT time or Z-time (Zulu) are the same everywhere. Time zone adjustments are just a presentation level details. – jww Feb 14 '14 at 09:04

1 Answers1

0

The handling is usually two fold. To handle it on server side, you'll need reliable time zone information. This is usually obtained from the user's preferences for time zone in their profile page.

Having said that we need to make sure that all date data captured on client side and when stored in DB is in UTC format. JS functions have a ready support for the UTC datetime.

When you store you use UTC() method in JS to get date.

When displaying back either you supply the time-zone equivalent from DB(based on stored user time zone data) or use JS to get it from the browser locale like this

<script type="text/javascript">
        function showDateInClientSideFormat(dValue)
        {
            var d = new Date()
            var n = d.getTimezoneOffset();
            var dateClientSide = new Date(dValue +n);
            return dateClientSide;
        }
    </script>

Also see my answer here https://stackoverflow.com/a/21573366/1123226

Community
  • 1
  • 1
DhruvJoshi
  • 17,041
  • 6
  • 41
  • 60