Timestamp from the web browser?
Possible Duplicate:
How can I determine a web user's time zone?
How do you get a timestamp in JavaScript?
I would like to get the timestamp from my user web browser.
Example: If now a user comes to my website from USA and another comes from Spain, I would like to save the respective time and date that it is now in USA and Spain.
只需使用new Date().toString()
;
Getting the time with JavaCcript returns the current user's machine time.
The following JavaScript code will return the number of milliseconds since midnight Jan 1, 1970.
var timestamp = new Date().getTime();
Now just grab the timestamp
variable and send it back to your webserver, if that's where you want to save this information. The easiest unobtrusive way I can think of to do this is by using ajax to POST the time information back to your server, for example (using jQuery):
$.post("saveusertime.php", { time: timestamp} );
Sources
JavaScript's Date Object: http://www.w3schools.com/jsref/jsref_obj_date.asp
jQuery's post() function: http://api.jquery.com/jQuery.post/
链接地址: http://www.djcxy.com/p/13564.html下一篇: Web浏览器的时间戳?