Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
OpptyCloseTimerCmpHelper
var interval = window.setInterval(
$A.getCallback(function() {
//Fomart the Opportunity Close Date
var opptyCloseDate = new Date( closeDate+" 00:00:00 ");
//Todays date
var now_date = new Date();
// time difference between opportunity close date and today's date
var timeDiff = opptyCloseDate.getTime()- now_date.getTime(); //Return the number of milliseconds since 1970/01/01
component.set("v.isValid",true);
//seprate the timeDiff into total seconds, minnutes, hours and days.
var seconds=Math.floor(timeDiff/1000); // seconds
var minutes=Math.floor(seconds/60); //minute
var hours=Math.floor(minutes/60); //hours
var days=Math.floor(hours/24); //days
//get the remaining hours, minutes, seconds.
hours %=24;
minutes %=60;
seconds %=60;
//put the calculated value in lightning component Attributes.
component.set("v.day",days);
component.set("v.hour",hours);
component.set("v.minute",minutes);
component.set("v.second",seconds);
}), 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment