jQuery.countdown icon indicating copy to clipboard operation
jQuery.countdown copied to clipboard

Set Multiple instances on the same page with Timezone Aware

Open karlosuccess opened this issue 7 years ago • 1 comments

I need to set jQuery.countdown Multiple instances on the same page with Timezone Aware using MomentJS as per the documentation in the website:

So far I have this:

<div data-countdown="2018-01-01 12:00:00"></div>
<div data-countdown="2019-01-01 12:00:00"></div>
<div data-countdown="2020-01-01 12:00:00"></div>

<script>
jQuery( document ).ready(function() {

    jQuery("[data-countdown]").each(function() {

        var jQuerythis = jQuery(this), finalDate = jQuery(this).data("countdown");

        finalDate = moment.tz(finalDate, "Europe/London"); // <-- ***THIS IS NOT WORKING***

        jQuerythis.countdown(finalDate, function(event) {           
            jQuerythis.html(event.strftime("%D days %H:%M:%S"));            
        });

    });

});             
</script>

But it is not working. I don't think the follwing line is overall correct:

finalDate = moment.tz(finalDate, "Europe/London");

MomentJS is installed properly and if I remove the one line above everything works but without timezone awareness.

Could you provide with some suggestions please? Please help. Thank you!

karlosuccess avatar Dec 16 '17 00:12 karlosuccess

To whoever needs it, I was missing this portion ".toDate()" in the following line:

jQuerythis.countdown(finalDate.toDate(), function(event) {

I found the solution with help from this article Final Countdown jQuery plugin Multiple instances on the same page with Timezone Aware.

So now everything works beautifully!

jQuery.countdown Multiple instances on the same page with Timezone Aware (MomentJS).

Thanks to everybody that helped!

karlosuccess avatar Dec 16 '17 01:12 karlosuccess