Use toPrecision to set the date precision : Date Get « Date Time « JavaScript DHTML






Use toPrecision to set the date precision

 

<html>
<head>
    <title>the date</title>
    <script type = "text/javascript">
    var started = new Date();
    var now = started.getTime();
    </script>
</head>
<body>
    <p id="dateField"></p>

    <script type = "text/javascript">
    var bottom = new Date();
    var diff = (bottom.getTime() - now)/1000;
    var finaltime = diff.toPrecision(5);
    var dateLoc = document.getElementById("dateField");
    dateLoc.innerHTML = "Time: " + finaltime + " seconds.";
    </script>

</body>
</html>

   
  








Related examples in the same category

1.Get Day
2.Get Seconds
3.Get Month
4.Get Milliseconds
5.Get Full Year
6.Get Year
7.Get Time
8.To Date Source
9.Convert Date to Locale String()
10.Value Of a Date
11.Readable date value
12.Output date and time in a human readble form
13.Make the time readable
14.Local time and local date