Finding the number of seconds and milliseconds

Finding the number of seconds and milliseconds cover image
  1. Home
  2. JavaScript
  3. Finding the number of seconds and milliseconds

Format #9: Finding the number of seconds and milliseconds

getSeconds() and getMilliseconds() return the seconds and milliseconds values.

<script type="text/javascript">
<!--

var d = new Date();
var curr_hour = d.getHours();
var curr_min = d.getMinutes();

var curr_sec = d.getSeconds();
var curr_msec = d.getMilliseconds();

document.write(curr_hour + ":" + curr_min + ":" 
+ curr_sec + ":" + curr_msec);

//-->
</script>

Prints:

Sponsored Links

Format #10: GMT Time

Each of the methods discussed so far calculates time on the client-side (browser). JavaScript also supplies us, similar methods for finding the GMT (called the Universal Coordinated Time or UTC).

You can use these methods to find the GMT and format it based on scripts discussed before.

JavaScript