【问题标题】:Get User's Date & Time in User' TimeZone [duplicate]在用户的时区中获取用户的日期和时间 [重复]
【发布时间】:2016-10-12 12:18:15
【问题描述】:

我需要我的网站用户填写<form/> 的当前日期时间。日期时间应该是用户的时区
我需要在不设置 TimeZone 的情况下获取 DateTime

当我使用时

date("Y-m-d H:i:s")

它只返回 IST 中的 DateTime。 用户来自印度、美国还是英国。

我需要用户时区的当前日期时间。

我需要将值插入 MySql 中的 datetime 字段

我没有要求用户时区,而是我需要用户时区的日期和时间

【问题讨论】:

  • 我没有要求用户时区,而是我需要用户时区的日期和时间

标签: php mysql datetime


【解决方案1】:

您至少有两种快速解决方案:

  1. browsecap 或http://smart-ip.net/geoip-api 这个api返回你的用户IP地址对应的时区
  2. 您可以使用 javascript 并将有关日期的信息发送到您的 php 脚本:

    new Date().getTimezoneOffset(); - 时区偏移:) new Date().toString() - 返回 2016 年 6 月 11 日星期六 20:04:35 GMT+0200 (CEST)

【讨论】:

    猜你喜欢
    • 2013-03-27
    • 2013-08-17
    • 2019-03-13
    • 2011-06-12
    • 2012-10-08
    • 2014-01-17
    • 2010-12-22
    • 2018-10-27
    • 2011-02-28
    相关资源
    最近更新 更多