Foxpro Foxpro - 5 months ago 37
jQuery Question

How to set a countdown timer with a start date to an end date?

I'm using a countdown plugin but I want to create a future countdown start date > end date. For example if now [

2015/05/16 00:00:00
] I want to create start date [
2015/06/16 00:00:00
] to end date [
2015/07/16 00:00:00
] to show
div
content and also hide other
div
content before start date and after end date.

Also searched another plugins :


  1. https://github.com/Reflejo/jquery-countdown

  2. http://keith-wood.name/countdown.html

  3. http://rendro.github.io/countdown/

  4. https://github.com/tomgrohl/jCountdown


Answer

This Code would only start the countdown when the actual day is between the start- and enddate and will work for the jQuery countdown.

<div id="element"></div>
<script type="text/javascript">
    var startdate = "2015/06/16",
        enddate = "2015/07/16";
    if(new Date() >= new Date(startdate) && new Date() <= new Date(enddate)) {
        $("#element")
        .countdown(enddate, function(event) {
            $(this).text(
                event.strftime('%D days %H:%M:%S')
            );
        });
    }
</script>
Comments