문제

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));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top