Blogger Information
Blog 56
fans 7
comment 11
visits 222933
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP常见的日期处理
樂成的开发笔记
Original
1679 people have browsed it

PHP常见的日期处理

实例

<?php
header('Content-Type:textml; charset=utf-8;');
date_default_timezone_set('PRC');
$date_before = date('Y-m-01', strtotime('-1 month'));
echo " 本月共有:".date("t")."天";
echo " 当前年份".date('Y');
echo " 当前月份".date('m');
echo " 当前几号".date('d');
echo " 上个月1号".$date_before;
$date=date_create($date_before);
date_add($date,date_interval_create_from_date_string("26 days"));
echo "--".date_format($date,"Y-m-d");

echo "上个月月末" .date('Y-m-d', strtotime("$date_before +1 month -1 day"));
echo "上个月28号" .date("Y-m-d",strtotime("$date_before   +27   day"));  
echo "<br/>";
$today = date("Y-m-d");
$BeginDate=date('Y-m-01', strtotime(date("Y-m-d")));//本月第一天
$date_before = date('Y-m-01', strtotime('-1 month'));//上月第一天
$date_d = date('d');//当前几号
$date_before28 = date("Y-m-d",strtotime("$date_before   +27   day"));//上个月28
$date_8= date("Y-m-d",strtotime("$BeginDate   +7   day"));//本月8号
$date_18= date("Y-m-d",strtotime("$BeginDate   +17   day"));//本月18号
echo " 今天".$today;
echo " 本月第一天".$BeginDate;
echo " 上月第一天".$date_before;
echo " 上月28号".$date_before28;                      
echo " 本月8号".$date_8; 
echo " 本月18号".$date_18;   
echo "<br/>";
?>

运行实例 »

点击 "运行实例" 按钮查看在线实例


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post