JavaScript add minutes to date

Given a date and the task is to add minutes to it. To add minutes to the date object in javascript, some methods are used which are listed below:

JavaScript getMinutes() Method: This method returns the Minutes (from 0 to 59) of the provided date and time. 

Syntax:

Date.getMinutes()

Parameters: This method does not accept any parameters.

Return value: It returns a number, from 0 to 59, representing the minutes.

JavaScript setMinutes() Method: This method set the minutes of a date object. This method can also be used to set the seconds and milliseconds. 

Syntax:

Date.setMinutes(min, sec, millisec)

Parameters:

  • min: It is required parameter. It specifies the integer representing the minutes. Values expected are 0-59, but other values are allowed.
  • sec: It is optional parameter. It specifies the integer representing the seconds. Values expected are 0-59, but other values are allowed.
  • millisec: It is optional parameter. It specifies the integer representing the milliseconds. Values expected are 0-999, but other values are allowed.
    min = -1, it means the last minute of the previous hour and same for the other parameters.
    If min value passed to 60, it means the first minute of the next hour and same for the other parameters.

Return Value: It returns the new date with updated minute which is set by setMinutes() method.

JavaScript getTime() method: This method returns the number of milliseconds between midnight of January 1, 1970, and the specified date. 

Syntax:

Date.getTime()

Parameters: This method does not accept any parameters.

Return value: It returns a number, representing the number of milliseconds since midnight January 1, 1970.

JavaScript setTime() method: This method set the date and time by adding/subtracting a defined number of milliseconds to/from midnight January 1, 1970.

Syntax:

Date.setTime(millisec)

Parameters: 

  • millisec: Number of milliseconds to add/subtract to the given date

Return value: It returns, representing the number of milliseconds between the date object and midnight January 1 1970. 

Example 1: This example added 4 minutes to the var today by using setTime() and getTime() method. 

html




<body style="text-align:center;" id=

Date.setMinutes(min, sec, millisec)
1
Date.setMinutes(min, sec, millisec)
2

Date.setMinutes(min, sec, millisec)

Date.setMinutes(min, sec, millisec)
4<
Date.setMinutes(min, sec, millisec)
6 style=
Date.setMinutes(min, sec, millisec)
9
Date.setMinutes(min, sec, millisec)
2

Date.getTime()
1
Date.getTime()
2

Date.setMinutes(min, sec, millisec)
4
Date.getTime()
4
Date.setMinutes(min, sec, millisec)
6
Date.setMinutes(min, sec, millisec)
2

Date.setMinutes(min, sec, millisec)

Date.setMinutes(min, sec, millisec)
4<
Date.setTime(millisec)
0 id=
Date.setTime(millisec)
3 style=
Date.setTime(millisec)
6
Date.setMinutes(min, sec, millisec)
2

Date.setMinutes(min, sec, millisec)
4
Date.getTime()
4
Date.setTime(millisec)
0
Date.setMinutes(min, sec, millisec)
2

Date.setMinutes(min, sec, millisec)

Date.setMinutes(min, sec, millisec)
4<<5 <6=<8
Date.setMinutes(min, sec, millisec)
2

Date.getTime()
1body1

Date.setMinutes(min, sec, millisec)
4
Date.getTime()
4<5
Date.setMinutes(min, sec, millisec)
2

Date.setMinutes(min, sec, millisec)

Date.setMinutes(min, sec, millisec)
4<
Date.setTime(millisec)
0 id=style2 style=style5
Date.setMinutes(min, sec, millisec)
2

Date.setMinutes(min, sec, millisec)
4
Date.getTime()
4
Date.setTime(millisec)
0
Date.setMinutes(min, sec, millisec)
2

Date.setMinutes(min, sec, millisec)

Date.setMinutes(min, sec, millisec)
4<=4
Date.setMinutes(min, sec, millisec)
2

Date.getTime()
1=7

Date.getTime()
1=9

Date.getTime()
1"text-align:center;"1

Date.getTime()
1"text-align:center;"3

"text-align:center;"

Date.getTime()
1"text-align:center;"6

Date.getTime()
1"text-align:center;"8

Date.getTime()
1id0

Date.getTime()
1id2

"text-align:center;"

Date.getTime()
1id5

id6id7

id6id9

id6

Date.setMinutes(min, sec, millisec)
01

Date.getTime()
1
Date.setMinutes(min, sec, millisec)
03

Date.setMinutes(min, sec, millisec)
4
Date.getTime()
4=4
Date.setMinutes(min, sec, millisec)
2

Date.getTime()
4body
Date.setMinutes(min, sec, millisec)
2

Output

JavaScript add minutes to date

Adding minutes to Date object

Example 2: This example adds 6 minutes to the var today by using setMinutes() and getMinutes() method.