简体   繁体   English

如何转换yyyy-MM-ddTHH:mm:ssZ到yyyy-MM-dd HH:mm:ss?

[英]How to convert yyyy-MM-ddTHH:mm:ssZ to yyyy-MM-dd HH:mm:ss?

Paypal returns a timestamp of the following format: Paypal返回以下格式的时间戳:

yyyy-MM-ddTHH:mm:ssZ

And I don't quite know what to do with it... 我不知道该怎么做...

How can I convert it to yyyy-MM-dd HH:mm:ss using my local timezone in php? 如何将它转换为yyyy-MM-dd HH:mm:ss在php中使用我当地的时区?

I'm tempted to preg_replace the mysterious letters, but something tells me there must a better way. 我很想preg_replace设置神秘的字母,但有些东西告诉我必须有更好的方法。 There also appears to be 8 hours difference to my zone which I'm not sure how to substract. 我的区域似乎也有8小时的差异,我不知道如何减去。

Use DateTime class to do your magic. 使用DateTime类来实现你的魔力。

$date = new DateTime('2012-09-09T21:24:34Z');
$date->format('Y-m-d'); # read format from date() function

You can use strtotime() to get a UNIX timestamp. 您可以使用strtotime()来获取UNIX时间戳。 From there you can do whatever you need: DateTime object, date() , etc. 从那里你可以做任何你需要的事: DateTime对象, date()等。

Example with date() : date()示例:

echo date('r', strtotime('2012-09-10T10:00:00Z'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM