0

I'm displaying entries from an RSS feed onto my site but the date that comes with each entry is in a non-standard format, so I'm having difficulty creating a new javascript date object from it.

Is it possible to convert the following date to a date object:

Thu, 20 Feb 2014 07:52:45 -0800

and output it into this format?:

Thu, 20 Feb 2014 15:52:45
mmmoustache
  • 2,273
  • 6
  • 41
  • 62

4 Answers4

4

Maybe you are looking for toUTCString:

(new Date('Thu, 20 Feb 2014 07:52:45 -0800')).toUTCString()
// "Thu, 20 Feb 2014 15:52:45 GMT"

Your date string is already in a format that Date understands.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
0

Your date is already readable to javascript so you need to do utcString of the date then replace utc part and parse as date to get the result in desired format like this:

console.log((new Date('Thu, 20 Feb 2014 07:52:45 -0800')).toUTCString().toString().replace('GMT',''));
Adesh Pandey
  • 769
  • 1
  • 9
  • 22
0

You might find this method getTimezoneOffset() on date useful.

For example where I am:

var dateObj = new Date();
dateObj.getTimezoneOffset(); //returns -330

i.e. 330 minutes - 5:30 hrs

Rakesh
  • 3,370
  • 2
  • 23
  • 41
-1
const today = new Date(new Date().setHours(0,0,0,0));
4b0
  • 21,981
  • 30
  • 95
  • 142
  • 4
    While this code may solve the question, [including an explanation](https://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. – 4b0 May 31 '19 at 09:08