Pure JS - Display Time Elapsed & Remaining
- Joel Lipman
- JavaScript
- Hits: 2227
This is an example of Javascript code to update and display the elapsed/remaining hours minutes and seconds in real-time.
Why?
I know there are a lot of articles out there that write about the same, but this is an example that I was coding and found to be one of the most reduced cut down formats I've made. I thought I'd make a note of it to not have to search elsewhere...
This example specifically displays the time remaining on an access_token which is generated from an OAuth 2.0 process. I want to display to the user how much time is left before another access token will be generated and how long ago was the last token created.
How?
So almost pure JS. I'm working out the seconds remaining and seconds elapsed in PHP first then passing these as two variables to the below code but you could get your values from anywhere: