Jump to content
Search Community

countdown formula changed to 'by date'

LK1037 test
Moderator Tag

Recommended Posts

The code below currently runs a countdown based on ## of days in milliseconds.

Instead, now I need this to calculate from a specified date ( Nov 24, 2019 at 10 a.m.) or a date span (Nov 24-31, 2019 at 10 a.m.) PST. 

 

I'm guessing this is the call, but not sure how to integrate it into the existing formula...

new Date('Nov 24, 2019 10:00:00').getTime()

 

Here's our current countdown:

 

// COUNTDOWN BY MILLISECONDS ---------------------------------

var count = { time: 1000 * 60 * 60 * 24};

function setTime() {
  var timeLeft = count.time;
  var days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
  timeLeft -= days * 1000;
  var hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  timeLeft -= hours * 60 * 60;
  var minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
  timeLeft -= minutes * 60;

 

Thanks to anyone who can lend some insight.

LK

 

Link to comment
Share on other sites

Thanks for your grace and being willing to wade in anyway — we're still trying to figure out what/where/when/why stuff is supposed to go.

 

So, to your answer, you mean like this?

 

var count = { new Date('Nov 24, 2019 10:00:00').getTime()};

function setTime() {
  var timeLeft = count.time;
  var days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
  timeLeft -= days * 1000;
  var hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  timeLeft -= hours * 60 * 60;
  var minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
  timeLeft -= minutes * 60;

Link to comment
Share on other sites

Well, what you have for count isn't a valid JS object. But besides that, yes :) 

 

var count = {time: new Date('Nov 24, 2019 10:00:00').getTime() };

function setTime() {
  var timeLeft = count.time;
  var days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
  timeLeft -= days * 1000;
  var hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  timeLeft -= hours * 60 * 60;
  var minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
  timeLeft -= minutes * 60;
 
  // Do whatever
  console.log(days, hours, minutes);
}

 

Link to comment
Share on other sites

Hmm, that blew up the countdown (days, min, hours).

I made a project in codepen so you can see what happend.

I just commented out the original countdown code that displays correctly.

 

https://codepen.io/sgbluq/project/editor/XRpRLq#

 

Ideally, this would countdown to a specified endDate (Nov 24, 2019 10:00:00 PST).

How do we make it only countdown within a specific startDate to endDate?

Link to comment
Share on other sites

LOL. No worries — we can't tell the difference yet, it's all just code to us--but we're progressing.

 

Hmm, that really broke it. It seems to start the count correctly, then trails off into chaos. https://codepen.io/sgbluq/project/editor/XRpRLq#

 

I understand you need to focus on other things... can you defer me to the forum I should have posted this on?

Link to comment
Share on other sites

13 minutes ago, LK1037 said:

Hmm, that really broke it. It seems to start the count correctly, then trails off into chaos.

I'm pretty sure the function is correct. So there must be something else wrong with your project. 

 

FYI your CodePen project isn't working because you didn't load TweenMax. You can view errors by using your browser's console (F12).

 

13 minutes ago, LK1037 said:

can you defer me to the forum I should have posted this on?

StackOverflow is good for general programming questions. But your question is fine for these forums, just not directly related to GSAP :) 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...