ItSolutionStuff.com

Moment Difference Between Two Dates in Hours Minutes and Seconds

By Hardik Savani • January 7, 2021
jQuery

Today, moment difference between two dates in hours minutes and seconds is our main topic. if you want to see example of moment difference between two times in minutes then you are a right place. this example will help you moment difference between two times in seconds. i explained simply step by step moment difference between two dates in seconds.

Here, i will give you simple example of jquery moment js difference between two dates in hours minutes and seconds using diff().

let's see both example with output:

Example:

<!DOCTYPE html>

<html>

<head>

<title>jquery moment example - ItSolutionStuff.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 - ItSolutionStuff.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>

Output:

Hours:39

Minutes:2391

Seconds:143512

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Moment JS Check if Date is Future or not Example

Read Now →

Moment JS Check if Date is Past or not Example

Read Now →

Moment JS Humanize Duration | Moment fromNow() Example

Read Now →

How to Get Next Month Date in Moment JS?

Read Now →

Moment JS Get Last Date of Month Example

Read Now →

Moment JS Get Month Name from Number Example

Read Now →

Jquery Moment Convert String to Date Example

Read Now →

JQuery Moment JS Subtract Seconds to Datetime Example

Read Now →

JQuery Moment Add Minutes to Datetime Example

Read Now →

JQuery Moment Subtract Month Example

Read Now →

JQuery Moment Subtract Days to Date Example

Read Now →