开发者

Converting from ISO C timestamp to integer epoch in PHP

开发者 https://www.devze.com 2023-02-07 18:14 出处:网络
I have a timestamp: 2009-01-31T00:00:00 to which I am appending \'+00:00\' in order to get it 开发者_如何学编程to ISO C, from which I would then like to get the epoch, so I can feed it to date(\'...

I have a timestamp:

2009-01-31T00:00:00

to which I am appending '+00:00' in order to get it 开发者_如何学编程to ISO C, from which I would then like to get the epoch, so I can feed it to date('...', timestamp) and generate the format I'd like.

What's the best way to go about this. I don't want to have to extract/string manipulation of the original timestamp.

TIA

Answer, Thanks shamittomar:

date('n/j/Y', strtotime($v['node']->field_pub_date[0]['value'] . '+00:00'));


Use strtotime. It parses about any English textual datetime description into a Unix timestamp

echo strtotime('2009-01-31T00:00:00+00:00');

This will show you the epoch as 1233360000.


$UST = new DateTimeZone('UTC');

$dateObj = new DateTime($cellDataOfficeAttributes['date-value'], $UST);
list($year,$month,$day,$hour,$minute,$second) = explode(' ',$dateObj->format('Y m d H i s'));


Not shure if this is the best option but seams to give the right result

$str = '2009-01-31T02:20:50';
$time = strtotime($str);
var_dump(date('d-m-Y h-i-s', $time));


What about http://php.net/strtotime?

0

精彩评论

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

关注公众号