1

I'm receiving a string containing date and time (in UTC format) for when something was created. The string looks like this: "Wed Mar 13 14:10:20 +0000 2013". Now, I need to convert that to a more readable format. Something like this "14:10, 13 Mar" or preferably "1 hour ago", "1 week ago" etc.

How do I do this?

Thanks.

xdazz
  • 158,678
  • 38
  • 247
  • 274
Aleksander
  • 2,735
  • 5
  • 34
  • 57

2 Answers2

0

Try this:

$dt = 'Wed Mar 13 14:10:20 +0000 2013';
echo date( 'h:i, d-M', strtotime( $dt ) );

The time difference will require more code.

J.D. Pace
  • 586
  • 1
  • 3
  • 17
0

Use the DateTime object. The constructor should be able to parse that timestamp, then you can mainpulate the date and output in any format you wish:

$date = new dateTime('Wed Mar 13 14:10:20 +0000 2013');
echo $date->format('h:i, d-M');

For relative times, see: Convert 2010-04-16 16:30:00 to "Tomorrow Afternoon"

Community
  • 1
  • 1
Terence Johnson
  • 1,637
  • 1
  • 16
  • 21