Learn how to find the number of seconds and milliseconds with the help of JavaScript and understand the time formats used by the language.
finding the number of seconds and milliseconds using javascript, time formats in javascript, getting current time and date using javascript
Finding the number of seconds and millisecondsGo to Finding the number of seconds and millisecondsHTML & JavaScriptGo to HTML and JavaScript tips and tricksTips and tricksGo to web development Tips and tricksHomepage

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 LANGUAGE="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>

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.


| Page 1 | Page 2 | Page 3 | Page 4 | Page 5 |

AddThis Social Bookmark Button


Page contents: Time formats in JavaScript. How to find the number of seconds and milliseconds using simple JavaScript code.

Page URL: http://www.webdevelopersnotes.com/tips/html/ finding_the_number_of_seconds_and_milliseconds.php3



Join Mailing List


Feedback/Questions




50+ web hosting FAQs

Search engine for your website

Free software from Google - The Google Pack Collection

Create your own search engine
Search WebDevelopersNotes.com