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 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #4 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
What are Big Data Clusters in SQL Server?SQL/MySQLHow to get front page or home page ID in WordPress?WordPressHow to create a smooth scrolling effect with CSS?CSSCreate a responsive image gallery using CSS gridCSSHow to use [] (square brackets) function in Envision Basic?Envision BasicAlternate Style Sheets in CSSCSSHow to undo Git Commits on Pantheon?MiscellaneousHow to hide a DIV on clicks outside of it using jQuery?jQueryIntroduction to Angular modules Part 3: NgModules vs JavaScript modules and Angular librariesAngular4 ways to create Date Objects in JavaScriptJavaScriptHow does Next.js load pages faster?NextJSHow to get Current Year, Month and Date in JavaScript?JavaScript