如何转换为UTC [英] How to Convert to UTC

查看:146
本文介绍了如何转换为UTC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在获得日期和时间来自各种来源的时间(例如,FTP服务器的文件日期/时间,收到的电子邮件日期/时间等),并且需要将它们全部存储为UTC(所以它们都有一个共同的参考)。我该如何做?为了正确地进行转换,我需要哪些信息。



这是一个PHP Web应用程序。所以我可以得到我的服务器的时区。我不知道下一步该怎么做以下是一些示例输入:


  1. 2010年6月28日,星期一12:39:52 +1200

  2. 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:

  1. Mon, 28 Jun 2010 12:39:52 +1200
  2. 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆