0

I need to save different date formats in ISO format but with out converting in native javascript date object (i.e. new Date()). I don't want to change the date values, just saving at it is but in a common foramt. I can't predict the date format, because it will coming from different RSS feeds

Example for formats :

var d1 = '2021-09-07T12:00:00+09:00';
var d2 = 'Thu, 09 Sep 2021 01:00:00 +1000';
var d3 = 'Thu, 09 Sep 2021 04:00:00 GMT';
var d4 = 'Thu, 09 Sep 2021 16:25:41 EDT';
var d5 = '2021-Sept-07';
var d6 = '09-09-2021';

console.log(new Date(d1).toISOString().slice(0, -5));
console.log(new Date(d2).toISOString().slice(0, -5));
console.log(new Date(d3).toISOString().slice(0, -5));
console.log(new Date(d4).toISOString().slice(0, -5));
console.log(new Date(d5).toISOString().slice(0, -5));
console.log(new Date(d6).toISOString().slice(0, -5));

2021-09-07T03:00:00
2021-09-08T15:00:00 // Date Change
2021-09-09T04:00:00
2021-09-09T20:25:41
2021-09-06T18:30:00 // Date Change
2021-09-08T18:30:00 // Date Change
dalvir
  • 242
  • 3
  • 8

0 Answers0