| 
       在php中如果要实现日期转换成时间戳我们可以直接使用strtotime函数,如果把时间戳转换成日期直接使用date()函数即可实现,下面我来给各们朋友介绍介绍. 
strtotime()函数 strtotime() 函数将任何英文文本的日期时间描述解析为 Unix 时间戳. 
实例代码如下: 
	
	- <?php 
 
	- echo(strtotime("now")); 
 
	- echo(strtotime("3 October 2005")); 
 
	- echo(strtotime("+5 hours")); 
 
	- echo(strtotime("+1 week")); 
 
	- echo(strtotime("+1 week 3 days 7 hours 5 seconds")); 
 
	- echo(strtotime("next Monday")); 
 
	- echo(strtotime("last Sunday")); 
 
	- ?> 
 
	 
 
输出: 
1138614504 
1128290400 
1138632504 
1139219304 
1139503709 
1139180400 
1138489200 
上面是把日期转换成时间戳了,我们也可以把如 2013-04-21这种转换成时间戳 
实例代码如下: 
	
	- $a = date(); 
 
	- $mk = strtotime($a) 
 
	 
 
要求只能在白天8:00-20:00发送短信,怎么样获得到每天的这段时间区间? 
实例代码如下: 
	
	- <? 
 
	- $y=date("Y",time());  
 
	- $m=date("m",time());  
 
	- $d=date("d",time());  
 
	- $start_time = mktime(9, 0, 0, $m, $d ,$y);  
 
	- $end_time = mktime(19, 0, 0, $m, $d ,$y); 
 
	- $time = time();  
 
	- if($time >= $start_time && $time <= $end_time)  
 
	- {  
 
	-  
 
	- }  
 
	- ?> 
 
	 
 
下面来介绍把时间戳转换成日期 
date()函数,此函数不但可以获取各种各样的时间日期之外,还可以进行日期转换呼 
实例代码如下: 
	
	- <? 
 
	- $time = time(); 
 
	- $date = date("Y-m-d",$time); 
 
	- echo 'www.vcphp.com 提示'.$date 
 
	- ?> 
 
	 
 
      
      (责任编辑:admin) |