Add link elements around tweet entities such as hash tags, mentions, and urls

The Twitter REST API returns a created_at date with each API call as part of the JSON response. The problem is that the date returned is not a standard format nor is it in a format that is pleasing or useful in most circumstances. The date returned by the API looks like this: “Wed Aug 29 17:12:58 +0000 2012”. The simplest way to address this is to simply create a PHP DateTime object using the created_on date.

$date = new DateTime( $tweet->created_at );
echo $date->format( 'M jS' );

This would print a date like “Jul 4th” although any valid PHP date formats could be passed to format().

Check out my post on adding entity links around a tweet!

Also see my PHP Twitter class on Github that extends Abraham’s Twitter OAuth library and adds date formatting and entity links automatically.