我想确定一个日期并计算出其星期数。
到目前为止,我有以下内容。它应该是42时返回24。
<?php $ddate = "2012-10-18"; $duedt = explode("-",$ddate); $date = mktime(0, 0, 0, $duedt[2], $duedt[1],$duedt[0]); $week = (int)date('W', $date); echo "Weeknummer: ".$week; ?>
数字反转是巧合吗?还是我快到了?
今天,使用PHP的DateTime对象会更好:
DateTime
<?php $ddate = "2012-10-18"; $date = new DateTime($ddate); $week = $date->format("W"); echo "Weeknummer: $week";
这是因为in中mktime(),它是这样的:
mktime()
mktime(hour, minute, second, month, day, year);
因此,您的订单是错误的。
<?php $ddate = "2012-10-18"; $duedt = explode("-", $ddate); $date = mktime(0, 0, 0, $duedt[1], $duedt[2], $duedt[0]); $week = (int)date('W', $date); echo "Weeknummer: " . $week; ?>