Tsukimoto Mitsumasa
Tsukimoto Mitsumasa

Reputation: 582

date format dilemma?

I have this date from twitter, this represents the exact date the tweet is published,

Sun, 01 Jul 2012 19:05:54 +0000

what I want is to make its format into MM/DD HH:MM, tried to look for php date formats but couldn't find a way to make it look exactly the way I want it to be. Can someone please help? Thanks.

Upvotes: 0

Views: 59

Answers (2)

bretterer
bretterer

Reputation: 5781

print date('m/d h:i',strtotime('Sun, 01 Jul 2012 19:05:54 +0000'));

The date function for php is a good place to find all sorts of information on this.

This would be pretty simple to search and figure it out. You are looking for a date... ahh, date, that is a php function. When you look that up you will see that it takes some params, a format and a time stamp. Well... You do not have a time stamp you have a string. how do i convert a string to time? Wait, there is a strtotime function in php. There you have it... run the date function in php with the way you want the date to look and then convert the string to timestamp with strtotime

Upvotes: 4

LSerni
LSerni

Reputation: 57418

<?php
    date_default_timezone_set("UTC");

    $string = "Sun, 01 Jul 2012 19:05:54 +0000";

    $timestamp = strtotime($string);

    print "Date is " . date("m/d H:i", $timestamp) . "\n";
?>

You may have to change timezone, and/or add/subtract seconds or use local time functions to convert between TZ's.

Upvotes: 0

Related Questions