php 日历重复_PHP 生成日历

效果如下:

7cfcdffa3a81464982afdded608eaf3d.png

PHP端代码:

/**

* 日历

*

* @param string month

*/

public static function day_report($params = [])

{

$month = $params['month'];

if (empty($month))

{

$month = date('Y-m');

}

$month_begin = strtotime($month . '-01');

$month_end = strtotime("+1 months", $month_begin) - 24*3600;

$dt_begin = $month_begin - (date('N', $month_begin)-1) * 24*3600;

$dt_end = $month_end + (7 - date('N', $month_end)) * 24*3600;

$today = strtotime(date('Y-m-d'));

$list = [];

$dt = $dt_begin;

while ($dt <= $dt_end)

{

$class = '';

if ($dt < $month_begin || $dt > $month_end)

{

$class .= ' other';

}

if ($dt == $today)

{

$class .= ' today';

}

if ($dt > $today)

{

$class .= ' future';

}

$list[] = [

'dt' => date('Y-m-d', $dt),

'day' => date('j', $dt),

'class' => $class,

];

$dt += 24*3600;

}

$list = array_chunk($list, 7);

// 月份选择

$month_val = strtotime($month . '-01');

$month_cur = date('Y年m月', $month_val);

$month_pre = date('Y-m', strtotime("-1 months", $month_val));

$month_next = '';

if ($month != date('Y-m'))

{

$month_next = date('Y-m', strtotime("+1 months", $month_val));

}

$data = [

'month' => $month,

'list' => $list,

'month_cur' => $month_cur,

'month_pre' => $month_pre,

'month_next' => $month_next,

];

return self::_success($data);

}

HTML端代码:

.h3-month

{

margin:10px 0;

}

.h3-month span

{

display:inline-block;

border-radius: 5px;

background-color: #eee;

border:solid 1px #ddd;

padding:0 10px;

font-size:0.9;

}

#tbDayList{

width:auto;

}

#tbDayList th{

font-size:30px;

}

#tbDayList .td-day{

width:100px;

height:10px;

line-height: 100px;

padding:0;

font-size:50px;

font-family:Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;

color:#72B9F7;

}

#tbDayList .other{

color:#999;

}

#tbDayList .future{

color:#bbb;

}

#tbDayList .today{

color:blue;

}

{ $month_cur }

{ if $month_next != '' }

{ /if }

周一周二周三周四周五周六周日

{ foreach $list as $week }

{ foreach $week as $r }

{ $r.day }

{ /foreach }

{ /foreach }

标签:begin,日历,list,month,strtotime,date,dt,PHP,生成

来源: https://www.cnblogs.com/zjfree/p/13197844.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值