Georg
Georg

Reputation: 648

Change Format of Facebook "end_time"

Can anyone suggest a function to convert this: "2012-01-27T08:00:00+0000" to "Jan 27"?

Upvotes: 0

Views: 542

Answers (2)

insomiac
insomiac

Reputation: 5664

This can be done by using two functions strtotime and date. Strtotime : http://php.net/manual/en/function.strtotime.php to convert the time to Unix timestamp
Date : to format specific date/time.

date('M d', strtotime('2012-01-27T08:00:00+0000'));

where M = Month and d = date

Upvotes: 3

bretterer
bretterer

Reputation: 5781

This is what I do with my paypal code which is about the same as here

function convertTime($time) {
    $time = urldecode($time);
    list($hour, $minute, $junk) = explode(':',$time);
    list($second, $month, $day, $year) = explode(' ',$junk);
    $day = explode(',',$day);
    $day = $day[0];

    $montharr = array('Jan'=>1,'Feb'=>2,'Mar'=>3,'Apr'=>4,'May'=>5,'Jun'=>6,'Jul'=>7,'Aug'=>8,'Sep'=>9,'Oct'=>10,'Nov'=>11,'Dec'=>12);
    $timestamp = mktime($hour, $minute, $second, $montharr[$month], $day+1, $year);

    return $timestamp;
}

Then you can change timestamp to what you want using the php date function

<?PHP
    date('F j', convertTime($end_time));

?>

I understand that there is a strtotime() function but this gives me a bit more control over things.

Upvotes: 0

Related Questions