javascript add seconds to time.

Ads
 

javascript add seconds to time.

<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.

View Answers

Ads









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
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 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
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
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
JavaScript add row to table
JavaScript add row to table       This section illustrates you how to add a new row to the existing...="javascript:addRow('table')">Add row</button> </html>
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
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 add method
JavaScript add method       The add() method is used to add an option to a dropdown list... to the select tag's. This button is calling JavaScript function addNew() and will add
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
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
JavaScript  clone JavaScript
add
How to add two int numbers in Java Example  How to add two int numbers in Java Example  Here is a java example that accepts two integer from the user and find their sum. import java.util.*; class AddNumbers
add
Java Program to add two numbers  Java Program to add two numbers  Here is a java example that accepts two integer from the user and find their sum. import java.util.*; class AddNumbers { public static void main
add
How to add two numbers in Java  add two number   Here is a java example that accepts two integer from the user and find their sum. import java.util.*; class AddNumbers { public static void main(String[] args
add
Java Example to add two numbers  Java Example to add two numbers  Here is a java example that accepts two integer from the user and find their sum. import java.util.*; class AddNumbers { public static void main
add
add two no in Java  Java Add Example that accepts two integer from the user and find their sum  Here is a java example that accepts two integer from the user and find their sum. import java.util.*; class AddNumbers
JavaScript remove method
JavaScript remove method       As JavaScript's add() method is used to add more option elements...;select> tag by using the method remove() of the JavaScript. Syntax
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
Javascript  How validations are done using javascript ,with example? and interview questions on javASCRIPT
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

Ads