How to calculate elapsed time in JavaScript?

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.


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.


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.


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 uninstall Cocoapods from the Mac OS? #4 How to Use SQL MAX() Function with Dates? #5 How to add Read More Read Less Button using JavaScript? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Apr 7 Solution for “Yarn build: Failed because of a stylelint error” Apr 7 Make sure your links have descriptive text Apr 7 How to add Laravel to WordPress using Sage theme (and install Tailwind CSS)? Apr 2 How to create a sidebar using pure CSS? Apr 1 How to switch dark and light themes using pure CSS? Apr 1 How to calculate elapsed time in JavaScript?

You might also like these

The 7 Security Objectives of Any Organization for IT and Network SecurityMiscDebugging in WordPress Part 2: WP_DEBUG_LOG and WP_DEBUG_DISPLAYWordPressCurrencyPipe in Angular 9 with ExamplesAngularHow to send and receive query strings via links in Angular 9?AngularHow to create a sticky menu pin using CSS?CSSHow to get category name using post id in WordPress?WordPressHow to get user’s Browser and Operating Systems information using PHP?PHPsubstring() Method in JavaScriptJavaScriptHow to add multiple Columns in CSS like Bootstrap?CSSHow to scroll contents of HTML body horizontally and vertically using JavaScript?JavaScriptGive buttons accessible namesUI/UXSolution for “Yarn build: Failed because of a stylelint error”WordPress