Timer Moment.js

by Kyros Koh

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.31/moment-timezone.min.js"></script>
<div data-countdown="04/12/2021 00:00:00"></div>

JavaScript

$(function(){
    $('[data-countdown]').each(function() {
        var $this = $(this), 
            countdown = $(this).data('countdown');

        // set the incoming date format as the 2nd paramater to the constructor
        var finalDate = moment.tz(countdown, 'MM/DD/YYYY HH:mm:ss', 'Asia/Singapore');
        
        $this.countdown(finalDate.toDate(), function(event) {
            var totalHours = event.offset.totalDays * 24 + event.offset.hours;
            $(this).html(event.strftime('Expires in ' + totalHours + ' hr %-M min'));
        });
    });
});