Skip to content

Instantly share code, notes, and snippets.

@wwdboer
Last active May 17, 2017 04:18
Show Gist options
  • Save wwdboer/4353522 to your computer and use it in GitHub Desktop.
Save wwdboer/4353522 to your computer and use it in GitHub Desktop.
WordPress: Twitter time ago
<?php
// Twitter date format example: "created_at": "Mon Jun 27 19:32:19 +0000 2011"
function from_apachedate( $date ) {
list( $D, $M, $d, $h, $m, $s, $y ) = sscanf( $date, "%s %s %2d %2d:%2d:%2d +0000 %4d" );
return strtotime( "$d $M $y $h:$m:$s" );
}
// human_time_diff is a WordPress function
echo human_time_diff( from_apachedate( $item->created_at ), current_time( 'timestamp' ) );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment