两个php日期控制类_PHP教程
class Calendar
{
var $month;
var $year;function __construct($year,$month)
{
$this->year=$year;
$this->month=$month;
}function endday()
{
$daydate=date("d",mktime(0,0,0,$this->month,35,$this->year));
$endday=35-$daydate;
return $endday;
}
function oneday_week()
{
$oneday_week=date("w",mktime(0,0,0,$this->month,1,$this->year));
return $oneday_week;
}
function title_link()
{
if(!isset($this->month) && !isset($this->year))
{
$this->year = date("Y");
$this->month = date("m");
}
$lastmonth=$this->month-1;
$nextmonth=$this->month+1;
$lastyear=$this->year;
$nextyear=$this->year;if($this->month {
$lastmonth=12;
$nextmonth=$this->month+1;
$lastyear=$this->year-1;
$nextyear=$this->year;
}
elseif ($this->month >= 12)
{
$lastmonth=$this->month-1;
$nextmonth=1;
$lastyear=$this->year;
$nextyear=$this->year+1;
}$str ="
";
$str.=""; ".$this->year."--".$this->month."
$str.="";
return $str;
}
function Show_Calendar()
{
echo "";
".$this->title_link()." "; ";
$weekarray=array("日","一","二","三","四","五","六");
for($k=0;$k {
echo ""; ".$weekarray[$k]."
}
echo "
for($i=0;$i {
echo ""; ";
for($j=1;$j {
$math=( $j - $this->oneday_week() ) + 7 * $i;
echo ""; ";
if($math endday() and $math>=1)
{
echo $math;
}
echo "
}
echo "
}
echo "
}
}/*$calendar=new Calendar($_GET['year'],$_GET['month']);
//$calendar->month=$_GET['month'];
//$calendar->year=$_GET['year'];
$calendar->Show_Calendar();*/
//第二个?>
实例二
header("content-type:text/html;charset=utf-8");
?>
if(!empty($_GET)){
$year = isset($_GET['year'])?$_GET['year']:date('y');
$month = isset($_GET['month'])?$_GET['month']:date('m');
$day = isset($_GET['day'])?$_GET['day']:date('d');
}
if(empty($year)){
$year = date('Y');
}
if(empty($month)){
$month = date('m');
}if(empty($month)){
$days = date('d');
}$start_weekday = date('w',mktime(0,0,0,$month,1,$year));
//echo $start_weekday;
$days = date('t',mktime(0,0,0,$month,1,$year));
//echo $days;
$week = array('日','一','二','三','四','五','六');
$i = 0;
$k = 1;
$j = 0;
echo '';
';
echo ''; '.$year.'年'.$month.'月'.'
echo ''; ';
for($i = 0;$i echo ''.$week[$i].' ';
}
echo '
echo '';
for($j = 0;$j echo ''.$j.' ';
}
while($k if($k == $day){
echo ''.$k.' ';
}else{
echo ''.$k.' ';
}
if(($j+1) % 7 == 0){
echo ''; ';
}
$j++;
$k++;
}
while($j % 7 != 0){
echo ''.$j.' ';
$j++;
}
echo 'echo '
'; ';
echo "".' ';
echo "".' ';
echo ''; ';
echo '';
echo '
echo "".'>>'.' ';
echo "".'>'.' ';
echo '
echo 'function lastYear($year,$month){
$year = $year-1;
return "year=$year&month=$month";
}
function lastMonth($year,$month){
if($month == 1){
$year = $year -1;
$month = 12;
}else{
$month--;
}
return "year=$year&month=$month";
}
function nextYear($year,$month){
$year = $year+1;
return "year=$year&month=$month";
}
function nextMonth($year,$month){
if($month == 12){
$year = $year +1;
$month = 1;
}else {
$month++;
}
return "year=$year&month=$month";
}?>
推荐阅读
-
php计算两个日期相差天数的方法_PHP教程
-
PHP之图片上传类(加了缩略图),_PHP教程
-
php通过array_merge()函数合并两个数组的方法,array_merge数组_PHP教程
-
sqlserver2005教程 php操作sqlserver关于时间日期读取的小小见解
-
php的类和对象翻译midiguy_PHP教程
-
可以让PHP编程事半功倍的类库_PHP教程
-
php中使用__autoload()自动加载未定义类的实现代码_PHP教程
-
PHP的Yii框架中YiiBase入口类的扩展写法示例,yiiyiibase_PHP教程
-
php读写excel类,支持多工作簿和自定义样式,读写excel_PHP教程
-
PHP中codeigniter文件上传类代码实例_PHP教程