Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing Twitter API Datestamp

I'm using the twitter API to return a list of status updates and the times they were created. It's returning the creation date in the following format:

Fri Apr 09 12:53:54 +0000 2010

What's the simplest way (with PHP or Javascript) to format this like 09-04-2010?

like image 683
Chris Armstrong Avatar asked Apr 09 '10 22:04

Chris Armstrong


People also ask

Are tweet IDs sequential?

Today, Twitter IDs are unique 64-bit unsigned integers, which are based on time, instead of being sequential. The full ID is composed of a timestamp, a worker number, and a sequence number.


1 Answers

Cross-browser, time-zone-aware parsing via JavaScript:

var s = "Fri Apr 09 12:53:54 +0000 2010";  var date = new Date(     s.replace(/^\w+ (\w+) (\d+) ([\d:]+) \+0000 (\d+)$/,         "$1 $2 $4 $3 UTC")); 

Tested on IE, Firefox, Safari, Chrome and Opera.

like image 76
Ates Goral Avatar answered Sep 20 '22 08:09

Ates Goral