javascript add seconds to time.

javascript add seconds to time.

I want to add seconds to time. How can I do this?

View Answers

May 14, 2012 at 5:28 PM

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

        if (newSec > 59) {
            var mins = parseInt(newSec / 60);
            var sec = newSec - mins * 60;
            var newMin = parseInt(minutes) + mins;

            if (newMin > 59) {
                var hrs = parseInt(newMin / 60);
                var min = newMin - (hrs * 60);
                var newHrs = parseInt(hours) + hrs;
            } else {
                newHrs = hours;
                min = newMin;

            }

        } else {
            newHrs = hours;
            min = minutes;
            sec = newSec;
        }

        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 + " : " + sec + " "
                + format);
    }
</script>
</head>
<body>
<h2>Add Seconds to current date and display..</h2>
Enter Seconds :
<input type="text" name="sec" id="sec">
<input type="button" value="Add Seconds" onclick="addSeconds()";>
</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 seconds which you want to add into current time.parseInt() is used to convert the value in integer. Simple add seconds into the current second by writing var newSec = parseInt(seconds) + parseInt(secs); you will get new second.Now you must check , seconds will not exceed to 59.If it is more than 59 then convert seconds into minutes and add it into current minutes and same procedure for hours.









Related Tutorials/Questions & Answers:
javascript add seconds to time.
javascript add seconds to time.  <html> <head> <title>Add seconds to current times</title> <script type="text/javascript...); } </script> </head> <body> <h2>Add Seconds to current
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...; </head> <body> <h2>Add Seconds to current date and display
Advertisements
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...; } document.write("Time : " + newHrs + " : " + min + " : " + seconds
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?   <html> <head> <title>Add hours to current times</title> <script type="text/javascript
Java add seconds to Date
used in date time manipulation. Here, we are going to add few seconds...Java add seconds to Date In this tutorial, you will learn how to add seconds... add() of Calendar class, we have added 56 seconds to the calendar which
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
maximum execution time of 30 seconds exceeded in php
maximum execution time of 30 seconds exceeded in php  My PHP program is taking long time to run it is giving following error: Maximum execution time of 30 seconds exceeded in php file How to resolve this issue? Thanks
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>... + " : " + seconds); </script> </html> Description: In javascript whenever you
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
Convert Time to Milliseconds
and seconds to milliseconds as shown below. We also want that the Time would... Convert Time to Milliseconds       In this section, you will learn to convert Time
C Current Time
example, the time() function determines the current time in seconds and assigns it to time_t type variable t. The ctime() function converts the number of seconds... C Current Time      
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
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
PHP Date and Time Date and time Tutorial
;  print(date("Current time is: H (hours), i (minutes), s (seconds... (minutes), 13 (seconds) mktime - get timestamp for date and time value... of seconds between the Unix Epoch (January 1 1970) and the time specified
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
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
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
javaScript+Html
. Add a timer using ExtJS to show Extâ??s alert after 10 seconds...javaScript+Html  print("code sample");(Use ExtJS 3 or 4) and create following (HTML, Javascript,ExtJS) a. Create a single page application divided
ModuleNotFoundError: No module named 'django-seconds-field'
ModuleNotFoundError: No module named 'django-seconds-field'  Hi...: No module named 'django-seconds-field' How to remove the ModuleNotFoundError: No module named 'django-seconds-field' error? Thanks   Hi
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
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
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

Ads