JQuery Moment Add Minutes to Datetime Example

11-Apr-2023

.

Admin

Hi Dev,

Now let's see example of jquery moment add minutes to datetime. We will show you jquery moment add minutes. step by step explain moment js add minutes to time. i would like to show you moment add minutes to current time. if you have question about moment js add minutes to current time then i will give simple example with solution.

Here, i will give you simple example of jquery moment js add() method for add minutes to date and jquery moment js subtract() method for subtract minutes from date.

So let's see bellow example with output:

Example 1: Add Minutes to Time


<!DOCTYPE html>

<html>

<head>

<title>JQuery Moment Add Minutes Example - NiceSnippets.com.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 Add Minutes Example - NiceSnippets.com.com</h1>

</body>

<script type="text/javascript">

var startDateTime = '22-01-2021 09:30:20'

var newDateTime = moment(startDateTime, "DD-MM-YYYY hh:mm:ss")

.add(10, 'minutes')

.format('DD/MM/YYYY hh:mm:ss');

console.log(newDateTime);

var currentDateTime = moment().add(10, 'minutes')

.format('DD/MM/YYYY hh:mm:ss');

console.log(currentDateTime);

</script>

</html>

Output :

22/01/2021 09:40:20

17/02/2021 11:03:47

Example 2: Subtract Minutes to Time

<!DOCTYPE html>

<html>

<head>

<title>JQuery Moment Add Minutes 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 Add Minutes Example - ItSolutionStuff.com</h1>

</body>

<script type="text/javascript">

var startDateTime = '26-12-2020 09:30:20'

var newDateTime = moment(startDateTime, "DD-MM-YYYY hh:mm:ss")

.subtract(10, 'minutes')

.format('DD/MM/YYYY hh:mm:ss');

console.log(newDateTime);

var currentDateTime = moment().subtract(10, 'minutes')

.format('DD/MM/YYYY hh:mm:ss');

console.log(currentDateTime);

</script>

</html>

Output:

22/01/2021 09:30:20

17/02/2021 11:03:47

It will help you....

#Jquery