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.


amazon

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 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS? #Aug 1 What is Zdog? #Aug 1 How to add before after image effect using pure CSS? #Jul 31 Add animation to your skills bar using CSS #Jul 31 Use SwiperJS to create mobile touch sliders fast
You might also like these
How to Clone Objects in PHP?MiscellaneousSorting Object Arrays in JavaScriptJavaScriptWhat’s new in Constructor in PHP 8?PHPSQL ANY OperatorSQL/MySQLFew more :nth-child examples in CSSCSSHow to create a for loop in SCSS (Sass)?SCSSThe Difference Between the echo and print Commands in PHPPHPThe actual difference between indexOf() and search() in JavaScriptJavaScriptCSS backface-visibility PropertyCSSHow to make a UILabel clickable in Swift 5?SwiftSteps to Secure a VPNMiscellaneous3 Common Usability Mistakes In Web DesignUI/UX