Share on Google+Share on Google+

ratna rathor
javascript add seconds to time.
1 Answer(s)      4 years and 11 months ago
Posted in : JavaScript Questions

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

Ads

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
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
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
add Buttons in JavaScript
add Buttons in JavaScript  How to add Buttons in JavaScript
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 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
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>
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
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
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
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...;Submit".. After click on the Add Button user can add the new
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
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 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
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
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
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
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
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
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
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
Tutorials   
Java Spring Hibernate Struts Training code for programming How can I dynamically load user-entered data as content of jquery dialog? java webcam integration question java coding Fix Scrollbar position in a checkboxList after postback Information Save Alert Country wise redirection to files Interface in javascript connect database with javascript Zip Code ZipCode how to validate the email login How to play FLV video files on Ipad using HTML code or javascript code? Nitobi Grid is not working in IE10/IE11 jquery issue plese help RegEx Tree structure from json whose parents can be dragged and dropped from child newyorklife insurance getElementById not working javascript code for search in html file Implement The Skeleton Code Implement This Skeleton Code Mobile Automation using Appium Computer forensic application Java: Searching a string from doc files java linked list urgent !!! java linked list urgent!!! library management library management library management library management question Html form using JavaScript to display the table content java how to prevent no from unroundin off on clicking text box again in JSP and Jquery graph generation from xml design file display data from database in textbox when id entered in textbox Javascript Code for all fields how to get HTTP GET request value using javascript array Javascript Querry autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me Create SpreadSheet same as excel using java applet Create SpreadSheet same as excel using java applet How to change focus among multiple select boxes? Write JQUERY Code Write JQUERY Code Converting jsp variable to java variable java

Ads

 
Advertisement null

Ads