Discuss Date with server timestamp. in the JavaScript Development forum on Dev Shed. Date with server timestamp. JavaScript Development forum discussing JavaScript and DHTML, AJAX, and issues such as coding cross-browser JavaScript.
Posts: 5,964
Time spent in forums: 2 Months 3 Weeks 2 Days 12 h 47 m 19 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 4851
I don't believe that a timestamp is a valid form of data for the Date () constructor (I think they all require a string). Consequently, it's probably just constructing with the current date.
Posts: 1,435
Time spent in forums: 1 Week 5 Days 3 h 49 m 16 sec
Reputation Power: 184
As sizablegrin said, the timestamp is not in the correct format for creating a new Date.
Quick guide for creating a date. As you can see, Date() will take a string, but it has to be in a specific format. It will not take in a single number.
Are you not getting a Javascript error after the page loads? (and perhaps every second afterwards).
Posts: 1,435
Time spent in forums: 1 Week 5 Days 3 h 49 m 16 sec
Reputation Power: 184
I apologize, I was unaware of that. Looking at your code, I assume you've already tested the output of mktime to ensure it was different than what Javascript was giving.
In that case, I can't see why it would be affecting it. When I return from class I'll try running it on my own PHP host to see if I can remedy the problem from there.
Posts: 5,964
Time spent in forums: 2 Months 3 Weeks 2 Days 12 h 47 m 19 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 4851
You are correct. It can take an integer.
Referring to both the PHP manual and the document you linked, I think this is what happens. (My system performs as yours, gives me the local time, despite the fact that my server is 3 timezones away).
The integer returned by MKTIME, as used, represents UTC.
The date object contains both UTC and local time (presumably as defined by the locale settings). The methods used are the local-time methods.
Posts: 38
Time spent in forums: 4 h 55 m 34 sec
Reputation Power: 0
Hey guys,
Thanks for still looking into this....
I've tried several methods and always the timestamp is ignored by JS
var date = new Date((timestamp-27000)); still outputs local time.
Quote:
The date object contains both UTC and local time (presumably as defined by the locale settings). The methods used are the local-time methods.
. Yea I was thinking that too, but I tried the getUTCHours() method and it gets the real GMT/UTC time and ignores the timestamp too. Passing a timestamp in the constructor seems rather pointless if there are no methods to take advantage of it.....
Posts: 5,964
Time spent in forums: 2 Months 3 Weeks 2 Days 12 h 47 m 19 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 4851
You aren't thinking. Suppose you call me and ask what time it is, not knowing what time zone I'm in. I get the UTC time and give it to you. You can either show it as UTC or your local time. Unless I modify it (correctly, to my local time) before I give it to you, you can't know what my time is.
Posts: 5,964
Time spent in forums: 2 Months 3 Weeks 2 Days 12 h 47 m 19 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 4851
Quote:
Originally Posted by PHP manual for mktime
int mktime ( [int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst]]]]]]] )
Returns the Unix timestamp corresponding to the arguments given. This timestamp is a long integer containing the number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified.
In your case, the time specified is nada. There is nothing here about the server considering its own time zone in providing this value. It is copying that value into a JS expression to be reproduced on the browser. Your browser uses this for a Date object. Your Date object can give you GMT (not precisely the same as UTC, incidentally, but synchronized frequently), or your Date object can give you the local time for that GMT time, according to your locale. If you want the server to give its local time, adjust the timestamp accordingly and feed THAT into your JS assignment.
You've gotten a lot of responses. That's hardly indicative of "no one on this forum knowing or caring." Because you're not paying attention, and because you're frustrated, you're making unwarranted remarks.
Last edited by sizablegrin : April 9th, 2007 at 10:16 PM.