PHP 时间和日期

<?php
	header("Content-type: text/html; charset=utf-8"); 
	date_default_timezone_set("PRC");
	//PHP提供了内置函数time()来取得服务器当前时间的时间戳。
	$curtime = time();
	echo $curtime;
	echo "<hr/>";

	//date() 函数用于格式化时间,返回一个字符串
	$date= date("Y-m-d H:i",$curtime);
	echo $date;
	echo "<hr/>";

	//mktime() 函数用于从日期取得时间戳,成功返回时间戳,不然返回 FALSE 
	// mktime(时, 分, 秒, 月, 日, 年)
	$mktime = mktime("21","50","18","12","30","2015");
	echo $mktime;
	echo "<hr/>";

	$datetime=date("Y-m-d H:i",$mktime);
	echo $datetime;
	echo "<hr/>";
	//strtotime() 函数用于将英文文本字符串表示的日期转换为时间戳
	$strtime = "2015-10-11 12:10";
	$timestr = strtotime("$strtime");
	echo $timestr;
	echo "<hr/>";

	echo date("Y-m-d H:i",$timestr);

	echo "<hr/>";
	
	//要求用户在登录网站在2小时后失效而须要从新登陆的例子
	$expiration = time()+2*3600;//获得当前时间延迟2小时候的时间戳
	echo $expiration;
?>


wKiom1ZO4h-C0ulhAAA4V7KsFw0953.png

相关文章
相关标签/搜索