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 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
How to modify navigation menus in WordPress?WordPressThe actual difference between indexOf() and search() in JavaScriptJavaScriptMiddleware in NextJSNextJSThe SQL EXISTS OperatorSQL/MySQLThe :last-of-type selectorCSSWhat’s a Strict mode in JavaScript?JavaScriptWordPress: How to get ACF field values from another post?WordPressinclude, include_once, require, require_once in PHPPHPWhat’s Interpolation in SCSS (Sass)?SCSSHow to create a simple text and image slider using CSS and JavaScript?CSSWhat are Controlled Components in React?ReactHow to make a UILabel clickable in Swift 5?Swift