问题描述
我正在获得日期和时间来自各种来源的时间(例如,FTP服务器的文件日期/时间,收到的电子邮件日期/时间等),并且需要将它们全部存储为UTC(所以它们都有一个共同的参考)。我该如何做?为了正确地进行转换,我需要哪些信息。这是一个PHP Web应用程序。所以我可以得到我的服务器的时区。我不知道下一步该怎么做以下是一些示例输入:
- 2010年6月28日,星期一12:39:52 +1200
- 2010-06-25 15:33:00
对于第一种情况,在那里应该是微不足道的,但第二个例子将被视为UTC(或任何其他默认时区)。这是我建议的:
date_default_timezone_set('UTC'); //设置默认时区
$ one = strtotime('Mon,28 Jun 2010 12:39:52 +1200');
$ two = strtotime('2010-06-25 15:33:00'); //已经UTC必须是...
$ one
$ two
将保存转换为UTC时区的通讯时间的时间戳。
I'm getting dates & times from various sources (e.g. file's date/time from FTP server, email's date/tiem received, etc.) and need to store them all as UTC (so they all have a common reference). How do I do this? What pieces of information do I need in order to properly do the conversion.
This is for a PHP web application. So, I can get my server's time zone. I'm not sure what to do next. Here are some sample inputs:
- Mon, 28 Jun 2010 12:39:52 +1200
- 2010-06-25 15:33:00
For the first case the offset is there so it should be trivial, the second example however will be considered as UTC (or any other default timezone). This is what I suggest:
date_default_timezone_set('UTC'); // set default timezone
$one = strtotime('Mon, 28 Jun 2010 12:39:52 +1200');
$two = strtotime('2010-06-25 15:33:00'); // Already UTC? Must be...
$one
and $two
will hold the timestamps of the correspondent time converted to the UTC timezone.
这篇关于如何转换为UTC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!