开发者

How to convert local time to UTC format?

I have date

$timeZome = timezone_open('Europe/Kiev');
$date开发者_StackOverflow中文版 = new DateTime();
$date->setTimezone($timeZome);
$date->setDate(2011, 06,25);
$date->setTime(11,35,00);

How to present like that?

20110625T040000Z


This will do what you want:

$date = new DateTime();
$date->setTimezone(new DateTimeZone('Europe/Kiev'));
$date->setDate(2011, 06,25);
$date->setTime(11,35,00);
$date->setTimezone(new DateTimeZone('UTC'));

echo $date->format('Ymd\THis\Z'); // format string to match question

It's pretty straightforward: set the date/time/zone, modify the timezone and format for printing.


You may just need to call format on your date object, I think.

echo $date->format('Ymd'); // 20110625

UPDATE: You may want to look into either using the existing constants in the date class, or if your needs differ from what date offers, simply extend it and add a method that parses and returns your date formatted as you want it to.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜