• <bdo id='MPdzD'></bdo><ul id='MPdzD'></ul>
    1. <i id='MPdzD'><tr id='MPdzD'><dt id='MPdzD'><q id='MPdzD'><span id='MPdzD'><b id='MPdzD'><form id='MPdzD'><ins id='MPdzD'></ins><ul id='MPdzD'></ul><sub id='MPdzD'></sub></form><legend id='MPdzD'></legend><bdo id='MPdzD'><pre id='MPdzD'><center id='MPdzD'></center></pre></bdo></b><th id='MPdzD'></th></span></q></dt></tr></i><div id='MPdzD'><tfoot id='MPdzD'></tfoot><dl id='MPdzD'><fieldset id='MPdzD'></fieldset></dl></div>
      1. <small id='MPdzD'></small><noframes id='MPdzD'>

        <legend id='MPdzD'><style id='MPdzD'><dir id='MPdzD'><q id='MPdzD'></q></dir></style></legend><tfoot id='MPdzD'></tfoot>
      2. 使用 JavaScript 或 PHP 自动检测用户当前的本地时间

        Automatically detect user#39;s current local time with JavaScript or PHP(使用 JavaScript 或 PHP 自动检测用户当前的本地时间)
        1. <small id='5xLgg'></small><noframes id='5xLgg'>

              <i id='5xLgg'><tr id='5xLgg'><dt id='5xLgg'><q id='5xLgg'><span id='5xLgg'><b id='5xLgg'><form id='5xLgg'><ins id='5xLgg'></ins><ul id='5xLgg'></ul><sub id='5xLgg'></sub></form><legend id='5xLgg'></legend><bdo id='5xLgg'><pre id='5xLgg'><center id='5xLgg'></center></pre></bdo></b><th id='5xLgg'></th></span></q></dt></tr></i><div id='5xLgg'><tfoot id='5xLgg'></tfoot><dl id='5xLgg'><fieldset id='5xLgg'></fieldset></dl></div>

              <legend id='5xLgg'><style id='5xLgg'><dir id='5xLgg'><q id='5xLgg'></q></dir></style></legend>

            • <tfoot id='5xLgg'></tfoot>

                <tbody id='5xLgg'></tbody>
                <bdo id='5xLgg'></bdo><ul id='5xLgg'></ul>

                  本文介绍了使用 JavaScript 或 PHP 自动检测用户当前的本地时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我经常需要根据不同时区的用户实际当地时间显示信息或受其影响.是否有可靠的方法来获取用户的当前时间和/或时区?

                  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's current time and/or timezone?

                  关键问题:

                  • 服务器端代码基于网站主机或用户的 ISP
                  • 客户端代码基于用户的系统时钟,太容易操纵了

                  关键问题:

                  • 是否需要精确定位用户的地理位置?
                  • ISP 时间可以作为准确的指南吗?
                  • 用户操作系统时钟可以变化或由用户修改?

                  例子:

                  倒计时:

                  仅剩 1 小时 3 分 56 秒!

                  Only 1 hour, 3 minutes, 56 seconds to go!

                  问题:秒走基于什么;用户的操作系统时钟、主机服务器时间(正负偏移)、ISP 系统时间.如果所有时区的时钟同时结束,这很容易,但如果它是用户本地时区午夜的倒计时,则更棘手)

                  Issue: seconds to go based on what; The user's OS clock, the hosts server time (plus or minus offset), ISP system time. This is easy if the clock finishes at the same time for all timezones, but trickier if it's a countdown to something like midnight in the user's local time zone)

                  编辑日志

                  项目于下午 3:03(10 秒前)发布

                  Item posted at 3:03pm (10 seconds ago)

                  问题:10 秒"的计算与用户无关,调整时间以匹配用户的时区.

                  Issue: "10 seconds" is calculated regardless of user, the time is adjusted to match the user's time zone.

                  开放时间:

                  这家餐厅现在营业至午夜(澳大利亚东部标准时间).

                  This restaurant is open now until midnight (AEST).

                  问题:可以通过从服务器端偏移来计算像午夜这样的时间,但使用像现在这样的 psudo 时间,2 小时内是基于用户的时间.

                  Issue: Giving a time such as midnight can be calculated by offsetting from the server-side but using psudo times such as now, in 2 hours is based on the user's time.

                  PHP: 使用 time() 输出服务器时间.这可以根据用户的时区进行偏移.

                  PHP: using time() outputs the server time. This can be offset depending on the user's timezone.

                  JavaScript: 使用 Date() 输出用户的计算机时钟时间,太容易操纵了.

                  JavaScript: using Date() outputs the user's computer clock time which is too easily manipulated.

                  推荐答案

                  总之没有.

                  我建议使用服务器端时间,并让用户能够选择他们的时区.

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

                  您可以根据用户 IP 地址的启发式方法计算用户的默认时区,但这很容易出错.

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

                  您应该能够通过 javascript/Ajax 提取客户端时区信息,但与时间本身一样,这也容易出错.

                  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.

                  这篇关于使用 JavaScript 或 PHP 自动检测用户当前的本地时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                    <i id='HeK0C'><tr id='HeK0C'><dt id='HeK0C'><q id='HeK0C'><span id='HeK0C'><b id='HeK0C'><form id='HeK0C'><ins id='HeK0C'></ins><ul id='HeK0C'></ul><sub id='HeK0C'></sub></form><legend id='HeK0C'></legend><bdo id='HeK0C'><pre id='HeK0C'><center id='HeK0C'></center></pre></bdo></b><th id='HeK0C'></th></span></q></dt></tr></i><div id='HeK0C'><tfoot id='HeK0C'></tfoot><dl id='HeK0C'><fieldset id='HeK0C'></fieldset></dl></div>
                    <tfoot id='HeK0C'></tfoot>

                      1. <legend id='HeK0C'><style id='HeK0C'><dir id='HeK0C'><q id='HeK0C'></q></dir></style></legend>
                          <tbody id='HeK0C'></tbody>

                        <small id='HeK0C'></small><noframes id='HeK0C'>

                          • <bdo id='HeK0C'></bdo><ul id='HeK0C'></ul>