javascript add hour to time

javascript add hour to time

I want to add numbers of hours to time. How can I do this using javascript?

View Answers

May 14, 2012 at 5:17 PM

<html>
<head>
<title>Add hours to current times</title>
<script type="text/javascript">
    function addHours() {
        var todayDate = new Date();
        var hrs = document.getElementById("hrs").value;
        var hours = todayDate.getHours();
        var newHrs = parseInt(hours) + parseInt(hrs);
        var minutes = todayDate.getMinutes();
        var seconds = todayDate.getSeconds();
            var format = "AM";

        if (newHrs > 11) {
            format = "PM";
            alert(newHrs);
        }
        if (newHrs > 12) {
            newHrs = newHrs - 12;
        }
        if (newHrs == 0) {
            newHrs = 12;
        }
        if (minutes < 10) {
            minutes = "0" + minutes;
        }
        document.write("Time : " + newHrs + " : " + minutes + " : " + seconds
                + " " + format);
    }
</script>
</head>
<body>
<h2>Add hours to current date and display..</h2>
Enter hours :
<input type="text" name="hrs" id="hrs">
<input type="button" value="Add Hours" onclick="addHours();">
</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 hours which you want to add into current time.parseInt() is used to convert the value in integer.Simple add hours into the current hour by writing var newHrs = parseInt(hours) + parseInt(hrs);









Related Tutorials/Questions & Answers:
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... to convert the value in integer.Simple add hours into the current hour by writing
javascript add minutes to time.
javascript add minutes to time.  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
Advertisements
javascript add seconds to time.
javascript add seconds to time.  <html> <head> <title>Add seconds to current times</title> <script type="text/javascript...("Time : " + newHrs + " : " + min + " : " + sec + " " + format
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 to current times</title> <script type="text/javascript"> function
about getting the hour time
about getting the hour time  if i want to say, if the hour shows before noon, display message "good morning" and if otherwise, display "good afternoon" and so on..and im using tag..the problem is i dont know the code for Good
How to add one hour in php date?
convert the 60 minute (one hour) into time. Then add the both to get and convert...How to add one hour in php date?  I have a date variable in PHP and I want to add one hour to it. What is the code for adding one hour to the PHP
PHP Date add 1 hour
In the following example code we are showing how you can add one hour... to add one hour to a date object $todayDate = date("Y-m-d g:i a"... into timeADS_TO_REPLACE_2 //echo "<br>".$currentTime; //Add one hour
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... for javascript time format am pm. Can you please explain the current time am pm
javascript current date and time.
javascript current date and time.  How can we display current date and time using javascript?   <html> <head> <title>Current date and time</title> </head> <script type="text/javascript
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
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... my doubts. how to calculate total hours by using start and end time field....total hours another textfiled in that i have to display total hour result. pls
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
Hour Format Example
Hour Format Example       This example shows how to format hour using Format class. In this program we use a pattern of special characters to time format. Description
Mysql Time Function
; Mysql Time Function is used to find the current time in hour, minute... time, From Unix Time in hour, minute and second.  Query to select Current... in set (0.00 sec) Query to converts the Time into Hour: The Query to returns
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
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
JavaScript Clock Timer
than 9, then it will add 0 in front of min, sec or hour value like 09 in the timer and it will add AM or PM according to the hour value. By using the JavaScript.../javascript"> function displayTime() { var date=new Date(); hour
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
calculate working hour
calculate working hour  why echo not come out? <html><body> <form action="<?php $_SERVER['PHP_SELF'];?>" method="post"> Working hour : <input name="workout" type="text"/><input name="submit1
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
ModuleNotFoundError: No module named 'api_hour'
ModuleNotFoundError: No module named 'api_hour'  Hi, My Python..._hour' How to remove the ModuleNotFoundError: No module named 'api_hour... to install padas library. You can install api_hour python with following
Convert Time to Seconds
Convert Time to Seconds       In this section, you will learn to convert Time to seconds. An hour has...: This example helps you in converting a Time to seconds. Here, first of all we have
Time validation
Time validation  Hi. I have a text box in html to get time in the format of hour:minutes. I have to validate that the given information in that text... project.   Here is a code that accepts the time in the format hh:mm
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
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
ModuleNotFoundError: No module named 'odoo10-addon-hr-holidays-hour'
ModuleNotFoundError: No module named 'odoo10-addon-hr-holidays-hour'  ...: No module named 'odoo10-addon-hr-holidays-hour' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-hr-holidays-hour' error
ModuleNotFoundError: No module named 'odoo10-addon-hr-holidays-hour'
ModuleNotFoundError: No module named 'odoo10-addon-hr-holidays-hour'  ...: No module named 'odoo10-addon-hr-holidays-hour' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-hr-holidays-hour' error
ModuleNotFoundError: No module named 'odoo11-addon-hr-holidays-hour'
ModuleNotFoundError: No module named 'odoo11-addon-hr-holidays-hour'  ...: No module named 'odoo11-addon-hr-holidays-hour' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-hr-holidays-hour' error
ModuleNotFoundError: No module named 'odoo11-addon-hr-holidays-hour'
ModuleNotFoundError: No module named 'odoo11-addon-hr-holidays-hour'  ...: No module named 'odoo11-addon-hr-holidays-hour' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-hr-holidays-hour' error
ModuleNotFoundError: No module named 'odoo11-addon-hr-holidays-hour'
ModuleNotFoundError: No module named 'odoo11-addon-hr-holidays-hour'  ...: No module named 'odoo11-addon-hr-holidays-hour' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-hr-holidays-hour' error
ModuleNotFoundError: No module named 'odoo12-addon-hr-holidays-hour'
ModuleNotFoundError: No module named 'odoo12-addon-hr-holidays-hour'  ...: No module named 'odoo12-addon-hr-holidays-hour' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-hr-holidays-hour' error
ModuleNotFoundError: No module named 'odoo12-addon-hr-holidays-hour'
ModuleNotFoundError: No module named 'odoo12-addon-hr-holidays-hour'  ...: No module named 'odoo12-addon-hr-holidays-hour' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-hr-holidays-hour' error
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
Convert Time to Milliseconds
Convert Time to Milliseconds       In this section, you will learn to convert Time to seconds. An hour has 3600 seconds, a minute has sixty seconds and a millisecond is one
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
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

Ads