Yogesh Chauhan's Blog

How to calculate elapsed time in JavaScript?

in JavaScript on April 1, 2021

I am going to make use of same function I created in this post:

How to create a simple stopwatch using JavaScript?

Let’s modify the code in the post above slightly to get what we want.

HTML

We’re going to show hours, minutes and seconds elapsed. You can add microseconds as well, just like the stopwatch example or just keep minutes and seconds.

CSS

Let’s give it a nice look using CSS. It’s not required for background processing for e.g. if you want to keep track of user’s timing activities.

JavaScript

Finally, let’s add the modified JavaScript function.

Here’s the demo and JavaScript code.


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
A complete guide to add responsive YouTube videos using HTML and CSSCSSHow to hide a DIV on clicks outside of it using jQuery?jQueryHow to add Go Back button in Swift 5?SwiftWhat Is a Graph Database?MiscellaneousHow to check if checkbox is checked or not using JavaScript?JavaScriptResponsive Masonry Grid using CSS columns PropertyCSSThe Difference Between the echo and print Commands in PHPPHPSolution to pod install fails with json error on Mac OS X 10.15 (or Mac OS Catalina)MiscellaneousHow to create a function in SCSS (Sass)?SCSSHow to create rotating texts using JavaScript and CSS?CSSMySQL queries to get data rows from previous month as well as from last 30 daysSQL/MySQLSafe Practice to add Links to cross-origin destinationUI/UX