Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JavaScriptQuestions javascript add seconds to time.
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


ratna rathor
javascript add seconds to time.
0 Answer(s)      2 years and 7 months ago
Posted in : JavaScript Questions


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


Advertisement
View Answers

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
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 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
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
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>
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
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...;Submit".. After click on the Add Button user can add the new
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 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
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
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
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
 

 

 

DMCA.com