Parsing Twitter API Datestamp

后端 未结 6 796
后悔当初
后悔当初 2020-12-04 22:33

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:

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 22:55

    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.

提交回复
热议问题