-
-
Save srujan21/e2a4ec5153a3f7f8aa699557b89716be to your computer and use it in GitHub Desktop.
Logic to implement timer in lightning component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
startTimer : function(component, event, helper) { | |
console.log('Timer started >>> ') | |
var countDownDate = new Date(new Date().getTime() + 2 * 60000); | |
console.log('countDownDate **** ' + countDownDate); | |
// Update the count down every 1 second | |
var timer = setInterval(function() { | |
// Get todays date and time | |
var now = new Date().getTime(); | |
// Find the distance between now and the count down date | |
var distance = countDownDate - now; | |
// Time calculations for days, hours, minutes and seconds | |
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); | |
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); | |
var seconds = Math.floor((distance % (1000 * 60)) / 1000); | |
// Display the result in the element with id="demo" | |
var timeLeft = minutes + "m " + seconds + "s "; | |
component.set("v.timeLeft", timeLeft); | |
}, 1000); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment