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

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
Is PHP still good for back-end programming?PHPHow to float an image around texts?CSSKeyValuePipe in Angular 9AngularThe order Property in Flex Items in CSSCSSHow to show and hide an element on click in React?ReactHow to detect the Blog Page in WordPress?WordPressHow to vertically align a html radio button to it’s label?CSSWhat is Zdog?MiscellaneousMySQL queries to get data rows from previous month as well as from last 30 daysSQL/MySQLWordPress: How to change a blog address (URL)?WordPressA quick introduction to API, REST API and PostmanMiscellaneousHow to retrieve homepage URL in WordPress?WordPress