0

I wanted to calculate the time differences (in minutes). However the data I gotten is not using a conventional time format, it is using the following format "yyyy-mm-dd-HH-MM-ss" in UTC time. I can't use this directly in moments or other library as seems. What is the recommendations to handle this specific format?

How can I use library such as "moment" to calculate the time differences with this time format from my data?

Calvin
  • 321
  • 2
  • 16

1 Answers1

2

Not sure but possibly try it with moment, something like:

const moment = require('moment');

const yourSpecialFormat = 'YYYY-MM-DD-HH-mm-ss';
const someDateInYourFormat = '2020-02-22-05-58-57';

let now = moment(moment().format(yourSpecialFormat), yourSpecialFormat);
let then = moment(someDateInYourFormat, yourSpecialFormat);

console.log('Hours   ----> ', moment.duration(now.diff(then)).asHours());
console.log('Minutes ----> ', moment.duration(now.diff(then)).asMinutes ());
Zeeshan Hassan Memon
  • 8,105
  • 4
  • 43
  • 57