I'm trying to modifie the JS script so I can get the date from a database instead of typing it manually. I don't really know how to get right format on the date. The plugin only use days, hours, minutes, seconds.
Is there someone that can help me?
Jquery countdown plugin
Original:
$(function () {
var austDay = new Date();
austDay = new Date(austDay.getFullYear() + 1, 1 - 1, 2);
$('#defaultCountdown').countdown({until: austDay});
$('#year').text(austDay.getFullYear());
});
</script>
Modified:
<?php $waa = '1441894898' ?>
<script>
$(function () {
var austDay = <?php echo json_encode($waa); ?>;
$('#defaultCountdown').countdown({until: austDay});
});
</script>
The plugin don't only use years, months, etc..., but a javascript Date
(reference here) instance. So if your $waa
variable is the date from what you want to count down, and it is in milliseconds, the var austDay = new Date(<?php echo $waa; ?>);
code should work.
That is mostly easily done with strtotime as it will pretty much recognize any time format you want. Then you can output it anyway you want. I use the following
date(MM/DD/YY, strtotime($waa))
For you it would most likely look like this
<?php echo json_encode(date(MM/DD/YY, strtotime($waa))); ?>
Not sure what format you need the date in but you can use the manual for date to get the format of the date you need right. (http://php.net/manual/en/function.date.php)