javascript add minutes to time.

javascript add minutes to time.

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

View Answers

May 14, 2012 at 5:21 PM

<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);









Related Tutorials/Questions & Answers:
javascript add minutes to time.
javascript add minutes to time.  I want to add minutes to time. How...;title>Add minutes to current times</title> <script type="text/javascript... + " " + format); } </script> </head> <body> <h2>Add minutes
javascript add hour to time
javascript add hour to time  I want to add numbers of hours to time...;title>Add hours to current times</title> <script type="text/javascript...; } document.write("Time : " + newHrs + " : " + minutes
Advertisements
javascript add seconds to time.
javascript add seconds to time.  <html> <head> <title>Add seconds to current times</title> <script type="text/javascript... will not exceed to 59.If it is more than 59 then convert seconds into minutes and add
javascript add seconds to time.
javascript add seconds to time.  I want to add seconds to time. How can I do this?   <html> <head> <title>Add seconds... will not exceed to 59.If it is more than 59 then convert seconds into minutes and add
Java add minutes to Date
used in date time manipulation. Here, we are going to add few minutes...Java add minutes to Date In this tutorial, you will learn how to add minutes... add() of Calendar class, we have added 56 minutes to the calendar which
javascript time with am pm
javascript time with am pm  How can I display current time with AM or PM using javascript?   <html> <head> <title>Time...; } if (minutes < 10){ minutes = "0" + minutes; } document.write("Time
javascript current date and time.
javascript current date and time.  How can we display current date and time using javascript?   <html> <head> <title>... + "/" + year); document.writeln("Time :- "+ hours + " : " + minutes
Add Date Time together
Add Date Time together  I want to add datetime with time and result... this in javascript. and first datetime is from the text box and another time is from second text box and add both the text box means datetime with time
add Buttons in JavaScript
add Buttons in JavaScript  How to add Buttons in JavaScript
add google map javascript
add google map javascript  How can i add google map using javascript in my web page?   Search for the " Google Maps Javascript API" it will allow you to embed the Google Map into your web Page
how to get time picker value in javascript of struts2
how to get time picker value in javascript of struts2  I am not able to get value of time picker in java script . my code is jsp java script var totime=dojo.widget.byId("totime").getValue(); how to get value please help me
calculate total hours by start time and end time in javascript - Ajax
calculate total hours by start time and end time in javascript  hi, i am doing Web surfing project. i used start and end timepicker field.it works... my doubts. how to calculate total hours by using start and end time field
JavaScript add row to table
JavaScript add row to table       This section illustrates you how to add a new row to the existing...;button onclick="javascript:addRow('table')">Add row</button>
JavaScript add row dynamically to table
JavaScript add row dynamically to table         We can add rows... to add row to a table dynamically then we can also do this with the JavaScript code
javascript
javascript  javascript code to dynamically add table on button click.../javascript/javascriptexamples/javascript-add-row-dynamically.shtml http://www.roseindia.net/javascript/javascript-add-row-to-table.shtml http://www.roseindia.net
converstion from minutes to days format
converstion from minutes to days format  i have one text field ,in that it taking time in seconds for example 1560 seconds,but i need in the format like example: 09days:10 hrs:10 mins. i need code for change this thankls
JavaScript Add Element to Array
JavaScript Add Element to Array       In the given JavaScript example, we have created an array... through the example you will learn about how to add element to an array using
JavaScript add method
JavaScript add method       The add() method is used to add an option to a dropdown list... JavaScript function addNew() and will add an option by getting the select tag element
Add and Delete Element Using Javascript in JSP
Add and Delete Element Using Javascript in JSP... developed an application to add and delete element using javascript . We created two... Javascript function addRow() and removeRow() for add and remove the person
JavaScript
JavaScript  clone JavaScript
time decrement
time decrement  i want to know calculate the time for 2 minutes(from current time started),after that the button in the page will be disable  ... minute. You can increase time interval as per your requirement.ADS_TO_REPLACE_1
JavaScript deleteCaption method
JavaScript deleteCaption method       As in the previous section of JavaScript method example you have seen that we can add the caption to our table at execution time
Javascript
Javascript  How validations are done using javascript ,with example? and interview questions on javASCRIPT
time
time  sir, i want to show system time on a textfield in awt(java). woulk you send me an example of time which can show time in standard format like H:M:S pls help me sir   Display time in JTextField import
calculate the time ..
calculate the time ..  [CODE] Elapsed Time Example <script type="text/javascript"> var startTime = null...() { startTime = new Date(); alert("Time Started
JavaScript
should use JavaScript? Thanks   Hi, JavaScript is scripting language that runs on browser. You have to embed JavaScript in HTML page. Please see JavaScript tutorial. Thanks
JavaScript
JavaScript  how to get full path of a file type in javascript
javascript
javascript  Hi deepak, how to write form validation on javascript
javascript
javascript  write a program to display implement about browsers using javascript
javaScript
javaScript  How to open a browser window that cannot be resized? (HTML + Javascript
javascript
javascript  i have just learned javascript... can you tell me what kind of applications can be made by javascript?? thank you
How can I learn Java in 5 minutes
programming language? I am wondering how much time it will take to learn Java for a beginner? So, searching good tutorials to learn Java in less possible time... learn Java in 5 minutes? Thanks
how to print of hours and minutes of 8725 seconds
how to print of hours and minutes of 8725 seconds  how to print of hours and minutes of 8725 seconds
how many hours and minutes in 8725 seconds
how many hours and minutes in 8725 seconds  how many hours and minutes in 8725 seconds? Thanks
javascript
javascript  how to set the request or session attribute in javascript head part of jsp page
javascript
javascript  Hi sir, This is sinduri, i want to learn javascript, so plz can u help me.how to learn
javascript
javascript  hi sir, if i want to learn javascript. what concepts i want to know
time
time  how to find the current system time between the user login and logout using java
Session time
Session time   I need to develop an application has a user id and password to login and maintain the session for 8 minutes. All the pages under the login are not available if there is no activity for 8 minutes
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
JAVASCRIPT
JAVASCRIPT  I have one textbox and I want to validate that it must start with number(1-0). can anyone tell me a javascript for that ? thanks in advance
Javascript
Javascript   Javascript to check Numeric entry in checkbox.....   Hi Please find the following code for numeric entry validation in javascript function validateBox(){ var data=document.myForm.someText.value
time
time format hh:mm:ss  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do?   Here is a jsp example that fetch the time from the database and display

Ads