Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][tlug] Getting a client and server to agree on UTC time
- Date: Sun, 19 Dec 2010 15:32:51 +0900
- From: Dave M G <dave@example.com>
- Subject: [tlug] Getting a client and server to agree on UTC time
- User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7
TLUG, I'm writing a Javascript application that talks to a PHP/MySQL server, and I need them to conform to using UTC time so that users across time zones can see information about other user's time without having to know what time zone each other is in. I display to the user everything time related in their local time, but that's only when displaying. Behind the scenes, everything is converted to UTC. I use a Unix time stamp, stored as a ten digit number in MySQL (not as a DATE field). I do all the time calculating within the PHP and Javascript code. Accuracy to seconds is good enough, so on the Javascript end, I convert from miliseconds to seconds. Here's the code I use to get the UTC time on the Javascript side: function convertLocalToUTC(timeInput) { return timeInput + (new Date().getTimezoneOffset() * 60); } The variable "timeinput" is a ten digit Unix time stamp. Theoretically, the Date().getImtezoneOffset() returns the number of minutes difference between now and UTC. Multiplying it by 60 turns it into seconds, and can be added to the number of seconds in the Unix time stamp. Here's the code I use to get the UTC time on the PHP side. $utcTime = time() - date("Z"); When I test on my local machine, everything works. But when I upload the PHP to a remote server (hosted in Boston), the times begin to disagree. They're off by a few hours. I think that my math is correct, so long as I'm working on the right assumptions about what UTC time values I should be getting back from date("Z") and getTimezoneOffset. However, since things aren't working as expected, my understanding of what those return must not be right. Of course, I've looked up on online guides and the PHP manual, but what I've read is what lead me to believe these should work in the first place. Can anyone point out where I'm going wrong? Any advice would be much appreciated. -- Dave M G
- Follow-Ups:
- Re: [tlug] Getting a client and server to agree on UTC time
- From: Edmund Edgar
- Re: [tlug] Getting a client and server to agree on UTC time
- From: Darren Cook
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] Javascript and I have different ideas about what "concatenate" means. [SOLVED]
- Next by Date: Re: [tlug] Getting a client and server to agree on UTC time
- Previous by thread: [tlug] Japan
- Next by thread: Re: [tlug] Getting a client and server to agree on UTC time
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links