phpjqueryjquery-countdown

jquery countdown invalid date countdown


I'm using jquery.countdown to create a countdown but it seems it shows the wrong date when making the countdown. What I have:

<?php 
$timestamp = strtotime(GetConfig($link, 'coming_soon_date'));
$formatted_date =  date('Y/n/j H:i:s', $timestamp);
?>

GetConfig will get the date in string format (2020/7/1).

After that, I have the following code in my javascript:

<script>
    $(document).ready(function() {
    var javascript_date = new Date("<?php echo $formatted_date; ?>");
    var releaseDate = javascript_date;



    $('#clockFlat').countdown(releaseDate).on('update.countdown', function(event) {
    var $this = $(this).html(event.strftime('<div class="clockCard px-1"> <span>%d</span> <br> <p class="bg-amber clockFormat lead px-1 black"> Day%!d </p> </div>'
        + '<div class="clockCard px-1"> <span>%H</span> <br> <p class="bg-amber clockFormat lead px-1 black"> Hour%!H </p> </div>'
        + '<div class="clockCard px-1"> <span>%M</span> <br> <p class="bg-amber clockFormat lead px-1 black"> Minute%!M </p> </div>'
        + '<div class="clockCard px-1"> <span>%S</span> <br> <p class="bg-amber clockFormat lead px-1 black"> Second%!S </p> </div>'))
    });


    });
</script>

It keeps telling me that's 1 day and 9 hours. What I'm doing wrong here?


Solution

  • The countdown starts. But instead of showing me 1 month and 12 days, it just shows me 1 day.

    The issue is that you have used %d for "days" - you need to use %D for number of days

    From: http://hilios.github.io/jQuery.countdown/documentation.html

    %d %-d Days left (taking away weeks)

    %D %-D Total count of days till the end

    so you would use %d in combination with %w (1 week 1 day) or $D without %w (8 days)