Moment JS fromNow() Example
Hii Guys,
In this example,I will learn you how to moment js humanize duration in laravel.you can easy and simply moment js humanize duration in laravel.
Here, i will give you simple example of jquery moment js fromNow() method provide you humanize duration.
Example :
<!DOCTYPE html>
<html>
<head>
<title>Moment JS Humanize Duration 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> Moment JS Humanize Duration Example - Nicesnippets.com</h1>
</body>
<script type="text/javascript">
var monthAgo = moment().subtract(2, 'months').fromNow();
console.log(monthAgo);
var startDateTime = '05-06-2021'
var dayAgo = moment(startDateTime, "DD-MM-YYYY") .fromNow();
console.log(dayAgo);
</script>
</html>
Output :
2 months ago
3 days ago
It will help you...
- How to set Date in setUTCHours() Method in JavaScript?
- How to Date sets UTC milliseconds in Javascript?
- How to Use push(), unshift(),pop() and shift() With Array in Javascript?
- How to Check if a Variable is a Number in Javascript?
- How To Format a Number Using Fixed - Point Notation in Javascript?
- How to Insert an Element into an Array in javaScript?
- How to remove duplicate elements from JavaScript Array?
- How to calculate years, months and days between two dates in javascript?