开发者

PHP Time Problem

well, I"ve got a time format of the type: 2011-02-16T01:25:50+04:00

I want to 开发者_运维百科strip the +04:00 from the end of the string. How to do it?

I am converting a timestamp from mysql to ISO 8601 format using this function:

$timeagotime = date('c',strtotime($row['created_at']));

where $timeagotime contains the value: 2011-02-16T01:25:50+04:00


Refer to the documentation for php's date function: http://php.net/manual/en/function.date.php

You need to use a different format string. For instance,

date('Y-m-d',strtotime($row['created_at']));

Givens you "2011-02-16". There are a number of format strings... check out the doc.


You could use substr() to remove it, or just generate a date without it in the first place, though you couldn't use the 'c' formatting option, since that'd just add the timezone on again.

$timeagotime = substr($timeagotime, 0, 19)

$timeagotime = date('Y-m-dTG:i:s', strtotime(...));


If you absolutely don't need the end then you can use the following. Otherwise I'd suggest using a different way to generate your date from the table. PHP Date

$timeagotime = substr(date('c',strtotime($row['created_at'])), 0, 19);

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜