<bdo id='WjJwS'></bdo><ul id='WjJwS'></ul>

      <tfoot id='WjJwS'></tfoot>

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

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

      1. 在 PHP/MySQL 中将日期时间存储为 UTC

        Storing datetime as UTC in PHP/MySQL(在 PHP/MySQL 中将日期时间存储为 UTC)
        <tfoot id='XfsxT'></tfoot>

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

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

                <bdo id='XfsxT'></bdo><ul id='XfsxT'></ul>

                • <i id='XfsxT'><tr id='XfsxT'><dt id='XfsxT'><q id='XfsxT'><span id='XfsxT'><b id='XfsxT'><form id='XfsxT'><ins id='XfsxT'></ins><ul id='XfsxT'></ul><sub id='XfsxT'></sub></form><legend id='XfsxT'></legend><bdo id='XfsxT'><pre id='XfsxT'><center id='XfsxT'></center></pre></bdo></b><th id='XfsxT'></th></span></q></dt></tr></i><div id='XfsxT'><tfoot id='XfsxT'></tfoot><dl id='XfsxT'><fieldset id='XfsxT'></fieldset></dl></div>
                  本文介绍了在 PHP/MySQL 中将日期时间存储为 UTC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我读到的所有关于将时间转换为用户时区的文章都说,最好的方法是以 UTC 存储日期和时间,然后将用户的时区偏移量添加到这个时间.

                  Everywhere I read about converting time to a user's timezone says that the best method is to store a date and time in UTC then just add the user's timezone offset to this time.

                  如何以 UTC 时间存储日期?我使用 MySQL DATETIME 字段.

                  How can I store a date in UTC time? I use the MySQL DATETIME field.

                  在我的 PHP 代码中向 MySQL 添加新记录时,我会使用 now() 插入 MySQL DATETIME.

                  When adding a new record to MySQL in my PHP code I would use now() to insert into MySQL DATETIME.

                  我需要使用不同于 now() 的东西来存储 UTC 时间吗?

                  Would I need to use something different than now() to store UTC time?

                  推荐答案

                  MySQL: UTC_TIMESTAMP()

                  MySQL: UTC_TIMESTAMP()

                  返回当前 UTC 日期和时间作为 'YYYY-MM-DD HH:MM:SS' 中的值或YYYYMMDDHHMMSS.uuuuuu 格式,取决于功能是否在字符串或数字上下文中使用

                  Returns the current UTC date and time as a value in 'YYYY-MM-DD HH:MM:SS' or YYYYMMDDHHMMSS.uuuuuu format, depending on whether the function is used in a string or numeric context

                  PHP:gmdate()

                  还有 PHP date_default_timezone_set() 在 PHP 中用于设置脚本的当前时区.您可以将其设置为客户端时区,以便所有格式化函数返回其本地时间的时间.

                  Also PHP date_default_timezone_set() is used in PHP to set the current time zone for the script. You can set it to the client time zone so all the formatting functions return the time in his local time.

                  事实上,虽然我很难让它发挥作用,而且总是会遇到一些问题.例如.从 MySQL 返回的时间信息未格式化为UTC",因此 strtotime 转换如果你不小心,它会变成当地时间.我很想知道是否有人对这个问题有一个可靠的解决方案,当日期跨越媒体边界时不会中断(HTTP->PHP->MySQL 和 MySQL->PHP->HTTP),同时考虑 XML 和 RSS/Atom.

                  In truth though I had a hard time getting this to work and always stumble into some gotcha. Eg. time information returned from MySQL is not formatted as 'UTC' so strtotime transforms it into a local time if you are not careful. I'm curious to hear if someone has a reliable solution for this problem, one that doesn't break when dates traverse media boundaries (HTTP->PHP->MySQL and MySQL->PHP->HTTP), also considering XML and RSS/Atom.

                  这篇关于在 PHP/MySQL 中将日期时间存储为 UTC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的问题)
                    • <legend id='vCtcW'><style id='vCtcW'><dir id='vCtcW'><q id='vCtcW'></q></dir></style></legend>
                        <bdo id='vCtcW'></bdo><ul id='vCtcW'></ul>

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

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

                          • <tfoot id='vCtcW'></tfoot>
                              <tbody id='vCtcW'></tbody>