Skip to main content
Participant
February 19, 2024
Answered

Canvas time counter to specific time

  • February 19, 2024
  • 1 reply
  • 272 views

Hi, 

I found this js code and now I need to use it in an Adobe Animate. If it is possible? If so, I would like to put the counter in an animated dynamic text box. 

<script>
// Set the date we're counting down to
var countDownDate = new Date("February 28, 24 21:35:00").getTime();

// Update the count down every 1 second
var x = setInterval(function() {

// Get today's 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 days = Math.floor(distance / (1000 * 60 * 60 * 24));
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"
document.getElementById("demo").innerHTML = hours + " godzin, "
+ minutes + " minut, " + seconds + " sekund ";

// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "End";
}
}, 1000);
</script>

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    Hi.

     

    You just need to use a dynamic text field instance on stage instead of a DOM element to display the calculated time. Like this:

    var root = this;
    
    // Set the date we're counting down to
    var countDownDate = new Date("February 28, 24 21:35:00").getTime();
    
    // Update the count down every 1 second
    var x = setInterval(function()
    {
    	// Get today's 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 days = Math.floor(distance / (1000 * 60 * 60 * 24));
    	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"
    	root.yourTF.text = hours + " godzin, " // CHANGE HERE
    	+ minutes + " minut, " + seconds + " sekund ";
    	
    	// If the count down is finished, write some text
    	if (distance < 0)
    	{
    		clearInterval(x);
    		root.yourTF.text = "End"; // CHANGE HERE
    	}
    }, 1000);

     

    Regards,

    JC

    1 reply

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    February 20, 2024

    Hi.

     

    You just need to use a dynamic text field instance on stage instead of a DOM element to display the calculated time. Like this:

    var root = this;
    
    // Set the date we're counting down to
    var countDownDate = new Date("February 28, 24 21:35:00").getTime();
    
    // Update the count down every 1 second
    var x = setInterval(function()
    {
    	// Get today's 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 days = Math.floor(distance / (1000 * 60 * 60 * 24));
    	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"
    	root.yourTF.text = hours + " godzin, " // CHANGE HERE
    	+ minutes + " minut, " + seconds + " sekund ";
    	
    	// If the count down is finished, write some text
    	if (distance < 0)
    	{
    		clearInterval(x);
    		root.yourTF.text = "End"; // CHANGE HERE
    	}
    }, 1000);

     

    Regards,

    JC

    Participant
    February 20, 2024

    You saved my ass... Thank you very much for your quick response!!!