WDN Logo

home-icon Home / JavaScript / Finding the number of seconds and milliseconds

Finding the number of seconds and milliseconds

Find the number of seconds and milliseconds in Javascript

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);



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

  • getUTCDate(): Date
  • getUTCMonth(): Month
  • getUTCFullYear(): Year (4 digit)
  • getUTCDay(): Day
  • getUTCHours(): Hours
  • getUTCMinutes(): Minutes
  • getUTCSeconds(): Seconds
  • getUTCMilliseconds(): Milliseconds

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

Sponsored Links


Your comments
Star icon IMPORTANT Have a question / problem? Click here to ask an expert.

Sometimes i just need a break

Sponsored Links


How do I view a deleted web page?
Is there a way to view a deleted web page - one that is no longer available? Yes there is and the solution is quite simple. [more...]


JavaScript was initially called LiveScript. The final name change is generally regarded as a clever marketing stunt by Netscape to ride on the popularity of Java, the hot new language at that time. So though the names are similar, JavaScript and Java have little in common. The language was created by Brendan Eich when he was working at Netscape Communications Corporation and it was first included in the beta releases of Netscape Navigator 2.0. Actually, if we go a little further in time, the language was called "Mocha" during development! JavaScript is now one of the most popular languages on the web and the term has been trademarked by Oracle Corporation. In the early days, Microsoft's implementation of the language was JScript. [more...]

Share on Whats app Share on Facebook Share on Twitter Share on Google plus