开发者

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

开发者 https://www.devze.com 2023-04-12 18:28 出处:网络
Does anyone kown in NodeJS, is there any way, server side script can retrieve client\'s time zone informatio开发者_C百科n from the ServerRequest object?

Does anyone kown in NodeJS, is there any way, server side script can retrieve client's time zone informatio开发者_C百科n from the ServerRequest object?

thanks


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号