日期与时间
1.取得和改变默认时区
date_default_timezone_get()
设定用于一个脚本中所有日期时间函数的默认时区

 
  
  1. <?php 
  2. date_default_timezone_set('PRC'); 
  3. $time=time(); 
  4. $formats=array
  5.              'U'
  6.              'r'
  7.              'c'
  8.              'l,F JS , Y, g:i A'
  9.              'H:i:s D d M y'
  10.              'm/j/y g:i:s a O (T)'
  11.              'Y-m-d H:i:s' 
  12. ); 
  13. foreach ($formats as $format){ 
  14.     echo "<p><b>$format</b>:".date($format)."</p>\n"
  15. ?> 


2.date()
 date 函数格式化参考表
http://bbs.itzk.com/thread-1547-1-1.html

 
  
  1. <?php 
  2. echo date("Y-n-d G:i:s"); 
  3. echo date('y-n-j'); 
  4. ?> 


3.gatdate()
格式:gatdate([int $timestamp])
根据给定时间戳$timestamp的值,返回一个完整的日期的关联数组

 
  
  1. <?php 
  2. $now=time(); 
  3. $array=getdate($now); 
  4. print_r($array); 
  5. ?> 


4.checkdate()
格式:boolean checkdate(int month,int day,int year);
检测一个日期格式是否争取,它接受的参数是月,日,年,返回的是一个布尔值

 
  
  1. <?php 
  2. $m=2; 
  3. $d=30; 
  4. $y=200; 
  5. echo "{$y}年{$m}月{$d}日"
  6. if (!checkdate($m$d$y)){ 
  7.    echo '输入的日期错误'
  8. }else { 
  9.     echo '输入的日期正确'
  10. ?> 


5.time()
返回系统当前时间

 
  
  1. <?php 
  2. $now=time(); 
  3. if (($now%2)==0){ 
  4.     echo "偶数秒"
  5. }else { 
  6.     echo "奇数秒"
  7. ?> 


6.mktime()
格式:mktime($hour,$minute,$second,$month,$day,$year)
此函数的作用与getdate()函数的功能正好相对,它由一系列的日期与时间值生成一个UNINX时间戳

 
  
  1. <?php 
  2. echo mktime(0,0,0,9,9,2010); 
  3. ?> 


7.strtotime()
此函数可將英文日期/时间字符串转换成UNIX时间戳
8.strftime()
將UNIX时间戳格式化成适用于系统当前环境的日期字符串
格式:strftime($format,$ts)

 
  
  1. <?php 
  2. setlocale(LC_TIME, "zhs"); 
  3. echo strftime("Month:%B"); 
  4. echo strftime("Day:%A"); 
  5. ?> 


9.gmmktime()
生成一个当前GMT即时时间的UNIX时间戳

 
  
  1. <?php 
  2. echo gmmktime(12,25,23,7,9,2011); 
  3. ?> 


10.gmdate()
將UNIX时间戳格式化成可阅读的日期字符串

 
  
  1. <?php 
  2. echo gmdate("d-M-Y h:i A",gmmktime()); 
  3. ?>