Moment JS Humanize Duration | Moment fromNow() Example

By Hardik Savani January 2, 2021 Category : jQuery

Hello,

In this example, you will learn moment js humanize duration. I’m going to show you about moment js from now example. This tutorial will give you simple example of moment js diff from now. This tutorial will give you simple example of jquery moment js diffForHumans.

Here, i will give you simple example of jquery moment js fromNow() method provide you humanize duration.

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 monthAgo = moment().subtract(1, 'months').fromNow();

console.log(monthAgo);

</script>

<script type="text/javascript">

var startDateTime = '01-01-2021'

var dayAgo = moment(startDateTime, "DD-MM-YYYY")

.fromNow();

console.log(dayAgo);

</script>

</html>

Output:

02-02-2021

02/2021

I hope it can help you...

Tags :
Shares