您的位置:首页 > 编程语言 > PHP开发

php根据给定日期获取给定日期本周的日期

2015-04-29 11:28 495 查看
<?php
class Calendar{
protected $_table1;//table表格
/*
* 根据日期获取一周的日期
*/
public function showOneWeek()
{
$week='2015-04-28';

$whichD=date('w',strtotime($week));
$weeks=array();
for($i=0;$i<7;$i++){
if($i<$whichD){
$date=strtotime($week)-($whichD-$i)*24*3600;
}else{
$date=strtotime($week)+($i-$whichD)*24*3600;
}
$weeks[$i]=date('Y-m-d',$date);

}
$this->_table1="<table style='width: 100%;'><tr>";
$this->_table1.="<tbody>";
foreach($weeks as $k=>$v){
$i=date('d',strtotime($v));
$this->_table1.="<td style='color:#ffffff;'><div style='margin-left: 30%;line-height: 30px;background-color: #005299;border-radius: 15px;height: 30px;text-align: center;width: 30px;'>$i</div></td>";
}
$this->_table1.="</tr></tbody></table>";
echo $this->_table1;
}
/**
* 输出日历
*/
public function showCalendar()
{
echo $this->_table;
}
}
$calc=new Calendar();
$calc->showOneWeek();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: