
I want to add minutes to time. How can I do this using javascript?

<html>
<head>
<title>Add minutes to current times</title>
<script type="text/javascript">
function addMinutes() {
var todayDate = new Date();
var mins = document.getElementById("mins").value;
var hours = todayDate.getHours();
var minutes = todayDate.getMinutes();
var newMins = parseInt(minutes) + parseInt(mins);
if (newMins > 59) {
var hrs = parseInt(newMins / 60);
var min = newMins - hrs * 60;
} else {
min = newMins;
hrs = 0;
}
var newHrs = parseInt(hours) + parseInt(hrs);
var seconds = todayDate.getSeconds();
var format = "AM";
if (newHrs > 11) {
format = "PM";
}
if (newHrs > 12) {
newHrs = newHrs - 12;
}
if (newHrs == 0) {
newHrs = 12;
}
if (min < 10) {
min = "0" + min;
}
document.write("Time : " + newHrs + " : " + min + " : " + seconds + " "
+ format);
}
</script>
</head>
<body>
<h2>Add minutes to current date and display..</h2>
Enter minutes :
<input type="text" name="mins" id="mins">
<input type="button" value="Add Minutes" onclick= "addMinutes();">
</body>
</html>
Description: In javascript whenever you write new Date() it shows the current date in standard format with current day,date,time and GMT.You can have your own format.
getHours() shows hours of specified date.
getMinutes() shows minutes of specified date.
getSeconds() shows seconds of specified date.
Input minutes which you want to add into current time.parseInt() is used to convert the value in integer. Simple add minutes into the current minutes by writing var newMins = parseInt(minutes) + parseInt(mins);
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.