1

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.

Community
  • 1
  • 1
Alex Marcos
  • 29
  • 1
  • 2

2 Answers2

1

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/

Telmo Marques
  • 5,066
  • 1
  • 24
  • 34
0

Just use new Date().toString();

Justice Erolin
  • 2,869
  • 20
  • 19