Moment Difference Between Two Dates in Hours Minutes and Seconds

14-Dec-2021

.

Admin

Now let's see example of moment difference between two dates in hours minutes and seconds. I will learn you how to get difference between two dates in hours minutes and seconds moment js. We will talk about difference between two dates in hours minutes and seconds using moment js.

Here, i will give you simple example of jquery moment js difference between two dates in hours minutes and seconds using diff(). So let's see both example with output:

Example:


<!DOCTYPE html>

<html>

<head>

<title>jquery moment example - Nicesnippets.com</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" crossorigin="anonymous"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" crossorigin="anonymous"></script>

</head>

<body>

<h1>jquery moment example - Nicesnippets.com</h1>

</body>

<script type="text/javascript">

var startTime = moment('02-01-2021 01:01:01', 'DD-MM-YYYY hh:mm:ss');

var endTime = moment('03-01-2021 16:52:53', 'DD-MM-YYYY hh:mm:ss');

var hoursDiff = endTime.diff(startTime, 'hours');

console.log('Hours:' + hoursDiff);

var minutesDiff = endTime.diff(startTime, 'minutes');

console.log('Minutes:' + minutesDiff);

var secondsDiff = endTime.diff(startTime, 'seconds');

console.log('Seconds:' + secondsDiff);

</script>

</html>

It will help you....

#Jquery