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

后端 未结 6 1271
逝去的感伤
逝去的感伤 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:43

    I would suggest you write the server date out to javascript. Then do a new date in javascript to get date set by user on their machine. Use the different in the two dates.

    With the server date you are sure that your time is unbiased. All calculations must be done using server date.

    User the difference only for display purposes. This would work well for edit logs, countdowns and selecting messages like "Good morning".

    If a user wants his time to be something else... I think you should let him have that.

提交回复
热议问题