当前位置:首页 > Web开发 > 正文

这段代码是把默认时区设置成了中国标准时间

2024-03-31 Web开发

//PRC是中国的意思,这段代码是把默认时区设置成了中国标准时间。
date_default_timezone_set(‘PRC‘);
/**
* 获取比来一周,一个月,一年
* */
function getLatelyTime($type = ‘‘){
$now = time();
$result = [];
if($type == ‘week‘){
//比来一周
for($i=0;$i<7;$i++){
$result[] = date(‘Y-m-d‘,strtotime(‘-‘.$i.‘ day‘, $now));
}
}elseif($type == ‘month‘){
//比来一个月
for($i=0;$i<30;$i++){
$result[] = date(‘Y-m-d‘,strtotime(‘-‘.$i.‘ day‘, $now));
}
}elseif($type == ‘year‘){
//比来一年
for($i=0;$i<12;$i++){
$result[] = date(‘Y-m‘,strtotime(‘-‘.$i.‘ month‘, $now));
}
}
return $result;
}


echo ‘<pre>‘;
print_r(getLatelyTime(‘year‘));

php 获取比来一周,一个月,一年

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/30682.html