1

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!

ketysek
  • 1,159
  • 1
  • 16
  • 46

1 Answers1

5

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');
Community
  • 1
  • 1
Anup Singh
  • 1,513
  • 3
  • 16
  • 32
  • great, first link works ... I've spent 2 hours on it :-/ ... but momentjs throws warning to console about using deprecated method and falling back to javascript Date, as I said – ketysek Apr 19 '17 at 09:58
  • moment.js will not throw the deprecated method error if you include the format as shown in the answer. – colemars Sep 22 '19 at 03:47