Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs, how to get client time zone info from its ServerRequest

Does anyone kown in NodeJS, is there any way, server side script can retrieve client's time zone information from the ServerRequest object?

thanks

like image 899
teleme.io Avatar asked Oct 12 '11 15:10

teleme.io


1 Answers

From the server request object? The only way I know of is to map the client's IP address, which you can get from:

var ip = request.header('x-forwarded-for');

... to the timezone using something like the geoip module. That module uses mindzone's GeoIP data, which, according to MindZone can provide Timezone strings. I don't know if the module API supports that, but in theory the data is there somewhere. It's just a matter of exposing it. If you need actually timezone time offsets, the time module is probably what you want.

Simpler (and probably more accurate), if you have JS running in the client, use Date.getTimezoneOffset and send that as part of your web request.

like image 145
broofa Avatar answered Sep 27 '22 01:09

broofa