Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何显示每个产品的计时器_Javascript_Php_Jquery - Fatal编程技术网

Javascript 如何显示每个产品的计时器

Javascript 如何显示每个产品的计时器,javascript,php,jquery,Javascript,Php,Jquery,我需要显示每个产品的计时器。。。 Bt当我把我的代码放入循环时,它只给一个产品计时。。。。 我需要在我的产品页面上显示每个产品的计时器…我正在创建一天的交易。。 我做了一些工作…它只工作一个产品。。。 我需要知道waht是给每一个产品计时的最好方式。。。 目前,我在我的上一个产品计时器 我的密码是贝娄。。 要计算日期差异,可以将日期字符串转换为时间戳(PHP=5.3,可以使用DateTime对象: 因为是时差,所以日期函数可能不是最好的方法。它生成的格式化日期正好是UNIX纪元时间后的$tim

我需要显示每个产品的计时器。。。 Bt当我把我的代码放入循环时,它只给一个产品计时。。。。 我需要在我的产品页面上显示每个产品的计时器…我正在创建一天的交易。。 我做了一些工作…它只工作一个产品。。。 我需要知道waht是给每一个产品计时的最好方式。。。 目前,我在我的上一个产品计时器

我的密码是贝娄。。


要计算日期差异,可以将日期字符串转换为时间戳(PHP<5.3):

$timespan
随后将保留给定两个日期之间的秒数,您可以进一步处理该值

对于PHP>=5.3,可以使用DateTime对象:


因为是时差,所以日期函数可能不是最好的方法。它生成的格式化日期正好是UNIX纪元时间后的
$timespan
秒。根据上下文的不同,它可能只显示小时、分钟和秒就足够了(因为这是一天中最重要的事情)。当我发布它的时候,我正在做一些事情哈哈。所以他需要将结果除以60得到分钟,然后再除以60得到小时,24得到天?有任何函数或shorcut用于此吗?您可以在php中使用
date\u diff
函数
<div class="row">
    <!-- <h3>New Products</h3> --> 
    <?php if ($this->getProducts()->getSize() > '0') { ?>

        <?php foreach ($this->getProducts() as $_Product) { ?> 

            <?php //echo $timespan = strtotime($_Product['special_to_date']) - strtotime($_Product['special_from_date']);exit; ?>
            <div style="float: left; margin-left: 10px;">
                <div><a href="<?php echo $_Product->getProductUrl(); ?>"><img src="<?php echo $this->helper('catalog/image')->init($_Product, 'small_image')->resize(145, 200) ?>" alt="<?php echo $_Product->getName(); ?>"></a></div>
                <div align="center"><h4><?php echo $_Product->getName(); ?></h4></div>
                <div align="center"><?php echo Mage::helper('core')->formatPrice($_Product->getPrice()); ?></div>
                   <?php // echo "<pre>"; print_r($_Product->toArray());exit; ?>
                <div id="timeremaining<?php echo $_Product['sku'] ?>"></div>
            </div>

            <script>
                var target_date = new Date('<?php echo $_Product['special_to_date'] ?>').getTime();
         //alert(target_date);
                var localMinDiff = new Date().getTimezoneOffset() * 60000;  // get the difference between local time and GMT >> in mins >> mins to milliseconds conversion
                target_date = target_date - localMinDiff;
                var days, hours, minutes, seconds;
                var countdown = document.getElementById("timeremaining<?php echo $_Product['sku'] ?>");

                var countdownTimer = setInterval(function() {
                    var current_date = new Date().getTime();
                    var seconds_left = (target_date - current_date) / 1000;

                    days = parseInt(seconds_left / 86400);
                    seconds_left = seconds_left % 86400;

                    hours = parseInt(seconds_left / 3600);
                    seconds_left = seconds_left % 3600;
                    minutes = parseInt(seconds_left / 60);
                    seconds = parseInt(seconds_left % 60);

                    if (days <= 0 && hours <= 0 && minutes <= 0 && seconds <= 0)
                    {
                        countdown.innerHTML = '';
                        clearInterval(countdownTimer);
                    }
                    else
                    {
                        if (days > 0)
                        {
                            days = days + 'Days,';
                        }
                        else
                        {
                            days = '';
                        }
                        countdown.innerHTML = '( ' + days + checkTime(hours) + ':' + checkTime(minutes) + ':' + checkTime(seconds) + ' remaining)';
                    }
                }, 1000);

                function checkTime(i) {
                    if (i < 10) {
                        i = '0' + i
                    }
                    ;
                    return i;
                }

            </script>

        <?php } ?>
    <?php } ?>
</div>
$timespan = strtotime($endDate) - strtotime($startDate);
$start = new DateTime($startDate);
$end = new DateTime($endDate);
$interval = $end->diff($start);
echo $interval->format("%d days, %h hours, %i minutes, %s seconds");