开发者

How to Convert to 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 prop开发者_JAVA技巧erly 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.


You can use strtotime() to convert whatever time format you have into a timestamp and then use whatever function, probably date(), to put it in the format you want everything to be stored in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜