Automatically detect user's current local time with JavaScript or PHP

后端 未结 6 1274
逝去的感伤
逝去的感伤 2020-11-29 04:54

I often need to display information based on or influenced by a user\'s actual local time which differs across time zones. Is there a reliable way of getting a user

6条回答
  •  没有蜡笔的小新
    2020-11-29 05:39

    In short no.

    I would suggest using server side time, and have the ability for the user to choose their time zone.

    You could possibly calculate default time zones for users based on heuristics around their IP address, but this is open to error.

    You should be able to extract client side time zone information through javascript / Ajax, but as with the time itself this is also open to error.

    My recommendation: Let users choose their time zone with a sensible default based on where you expect your users to be.

提交回复
热议问题