Search code examples
javascriptdatetwitter

Creating javascript Date object from Twitter API date – cross-browser solution


I've got a big problem with Twitter API created_at date, which has got following format: Tue Apr 18 07:24:05 +0000 2017 ... I want to create javascript Date object from that, but I'm not able to find cross-browser solution. What I've tried so far:

  • new Date(Date.parse(input.replace(/( \+)/, ' UTC$1'))); – returns null in Safari
  • new Date((input || "").replace(/-/g,"/").replace(/[TZ]/g," ")); – returns null in IE11
  • moment.js library throws warning about deprecated method and falls back to javascript Date()

Can someone help me to figure it out? Thank you very much!


Solution

  • follow these 2 links

    How to format Twitter/Facebook feed date with JavaScript

    JavaScript code to display Twitter created_at as xxxx ago

    OR USE momentjs.com

    > var tweetDate = 'Mon Dec 02 23:45:49 +0000 2013'; moment(tweetDate,
    > 'dd MMM DD HH:mm:ss ZZ YYYY', 'en');