Is it possible to determine user time from web request?

Is it possible on the web server to determine the local time and time zone of users when sending a request?

Can this be done using javascript to capture it and send it to the server?

My company wants to track how many users use our site outside of working hours (no, I don’t even know why this is so!).

Thanks.

+4
source share
6 answers

You need to put the JavaScript client time in a hidden field and assume that the clock is set correctly.

myTime = new Date() >> Tue Feb 03 2009 12:24:28 GMT-0500 (Eastern Standard Time) 
+6
source

You can load the date into a hidden field using JavaScript:

 var newDate = new Date(); hiddenFieldName.value = newDate.toLocaleString(); 

Then, in the reverse gear to the terminal, capture this field.

+2
source

You must consider the reverse DNS resolution of existing web server logs. Then you can use geocoding to guess the user's time zone (and their local time relative to the time of your web server).

You will not need to write new JavaScript code, write your own server-side code to register user time, and then deploy the updated website.

This Perl script can be a useful example: a Perl script that looks for massive reverse DNS queries

+2
source

JavaScript is really the way to go.

Fortunately, there are many code examples on the Internet that you can use . This page seems pretty comprehensive.

It should be noted that getting to know the current offset is not the same as knowing their time zone, but this is probably enough for your purposes :)

+1
source

Of course, you could embed the JS-based client’s timestamp and send it back to another request, but it’s completely unreliable since the user can set the time of his client to whatever he wants and requires that a second request, which could be slightly offensive, or technically inconvenient to provide. Many implementations will do this by fire and forgetting the AJAX request for a text file or adding a single empty pixel image to a page.

You can try to get a similar metric based on the first queries, and geolocation of the IP location and timestamp in time giving you local time - but it can be expensive if you do not already have an IP / Geo database :)

+1
source

Well, you can read the local time of the browser using JavaScript:

 var now = new Date(); 

Then you can send it to the server using XmlHttpRequest or a hidden form field ...

0
source

All Articles