首页 技术 正文
技术 2022年11月17日
0 收藏 853 点赞 4,183 浏览 1772 个字

一些日期的计算

某个月内的所有天数:

    public function getMonthDay ($date)
{
$stattime = strtotime(date('Ym01',strtotime($date .'01')));
$day = date('t',strtotime($date .'01'));
$i = 0;
$arr = [];
while ($i < $day) {
$arr[$i]['datetime'] = date('Ymd',$stattime + $i * 86400);
$i++;
} return $arr;
}

今日:图表X轴以小时为单位,每隔3小时显示一个数值。

 public function getToday ($date)
{
//今日:图表X轴以小时为单位,每隔3小时显示一个数值。
$today = strtotime ($date);
$todayEnd = strtotime ($date . '+1 day');
$hours = ($todayEnd - $today) / (3 * 3600); $i = 0;
$arr = [];
while ($i < $hours) {
$arr[$i]['starthour'] = date ('YmdH' , $today + $i * 3 * 3600);
$arr[$i]['endhour'] = date ('YmdH' , $today + (($i + 1) * 3 -1) * 3600);
$i++;
}
return $arr;
}

昨日:图表X轴以小时为单位,每隔3小时显示一个数值。

  public function getYesterday ($date)
{
//昨日:图表X轴以小时为单位,每隔3小时显示一个数值。
$today = strtotime ($date);
$yesterday = strtotime ($date .'-1 day');
$hours = ($today - $yesterday) / (3 * 3600); $i = 0;
$arr = [];
while ($i < $hours) {
$arr[$i]['starthour'] = date ('YmdH' , $yesterday + $i * 3* 3600);
$arr[$i]['endhour'] = date ('YmdH' , $yesterday + (($i + 1) * 3 -1)* 3600);
$i++;
} return $arr;
}

近1月:图表X轴以天为单位,每隔7天显示一个数值。

public function getMonth ($date)
{
//近1月:图表X轴以天为单位,每隔7天显示一个数值。
$mon = date ('Ym01' , strtotime ($date)); $month = strtotime(date('Ym01',strtotime($mon .'-1 month'))); //上个月第一天
$monthend = strtotime(date ('Y-m-t',$month)); // 上个月最后一天 $days = floor(($monthend - $month) / (7 * 24 * 3600));
if ($days<4) {
$days = 4; // 28天的月份
}
$i = 0;
$arr = [];
while ($i < $days) {
$arr[$i]['startdays'] = date ('Ymd' , $month + $i * 7 * 24 * 3600);
if($days==$i+1){
$arr[$i]['enddays'] = date('Ymd',$monthend);//上个月最后一天
}else{
$arr[$i]['enddays'] = date ('Ymd' , $month + (($i + 1) * 7-1) * 24 * 3600);
}
$i++;
} return $arr;
}

近6月:图表X轴以月为单位,每个月份显示一个数值。

 public function getSixMonth ($date)
{
//近6月:图表X轴以月为单位,每个月份显示一个数值。
$i = 0;
$arr = [];
$date = date('Y-m-01',strtotime($date));
while ($i < 6) {
$arr[$i]['startmonth'] = date ('Ym' , strtotime ($date .'-'. (6 - $i) . ' month'));
$arr[$i]['endmonth'] = date ('Ym' , strtotime ($date .'-'.(6 - $i) . ' month'));
$i++;
}
return $arr;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,120
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,592
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,437
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,208
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,844
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,929