I have a date as string like this:
2018-05-29-13-56-00
I need to convert this to epoch so I can make calculations with other dates.
Does anyone have an idea on how to do that? Thank you!
I have a date as string like this:
2018-05-29-13-56-00
I need to convert this to epoch so I can make calculations with other dates.
Does anyone have an idea on how to do that? Thank you!
You can do this. Note the d[1] - 1
because months are zero-based.
const date = '2018-05-29-13-56-00';
const d = date.split('-');
const epoch = (new Date(d[0], d[1] - 1, d[2], d[3], d[4], d[5])).valueOf();
console.log(epoch);
You can do this with moment.js
, if you are okay with using that library.
moment('2018-05-29-13-56-00', 'YYYY-MM-DD-hh-mm-ss').format();