Rasmus M Rasmus M - 11 days ago 4x
Ajax Question

Convert date string to year/month/day

Ajax getResponseHeader("Last-Modified") returns a date string in the following format:

Thu Oct 13 2016 13:05:17 GMT+0200 (Paris, Madrid, sommartid)

Is it possible with javascript to get the year, month and day so I can store them in separate variables?

let date = new Date('Thu Oct 13 2016 13:05:17 GMT+0200 (Paris, Madrid, sommartid)');

let year = date.getFullYear(); // result: 2016
let month = date.getMonth(); // 0-11 not 1-12! result: 9 while Oct is 10th
let day = date.getDate();    // result: 13

To work with dates I recommend http://momentjs.com/