Parsing Twitter API Datestamp

后端 未结 6 782
后悔当初
后悔当初 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:56

    JavaScript can parse that date if you remove the +0000 from the string:

    var dStr = "Fri Apr 09 12:53:54 +0000 2010";
    dStr = dStr.replace("+0000 ", "") + " UTC";
    var d = new Date(dStr);
    

    Chrome -- and I suspect some other non IE browsers -- can actually parse it with the +0000 present in the string, but you may as well remove it for interoperability.

    PHP can parse the date with strtotime:

    strtotime("Fri Apr 09 12:53:54 +0000 2010");
    

提交回复
热议问题