teleme.io
teleme.io

Reputation: 860

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

Upvotes: 12

Views: 8418

Answers (1)

broofa
broofa

Reputation: 38142

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.

Upvotes: 7

Related Questions