php getdate函数用法举例

发布时间:2020-06-16编辑:脚本学堂
本文介绍下php中getdate()函数的用法,举了几个小例子,供大家参考,以快速掌握getdate()函数的用法,有需要的朋友参考下。

1,输出月,日年
 

复制代码 代码示例:
<?php
$a = getdate();
printf('%s %d, %d',$a['month'],$a['mday'],$a['year']);
?>
 

 
2,getdate()使用指定的timestamp
 

复制代码 代码示例:
<?php
$a = getdate(163727100);
printf('%s %d, %d',$a['month'],$a['mday'],$a['year']);
?>

3,getdate()获取当前日期
 

复制代码 代码示例:
<html>
<head>
<title>getdate()获取当前日期-www.jb200.com</title>
</head>
<body>
<div>
<?php
$date_array = getdate();
foreach ( $date_array as $key => $val ) {
  print "$key = $val<br/>";
}
?>
<hr/>
<p>
<?
print "Today's date: ";
print $date_array['mon']."/".$date_array['mday']."/".$date_array['year'];
?>
</p>
</div>
</body>
</html>
 

附,getdate( )函数的返回值的对应关系
 

Key             Value
seconds         Seconds
minutes         Minutes
hours           Hours
mday            Day of the month
wday            Day of the week, numeric (Sunday is 0, Saturday is 6)
mon             Month, numeric
year            Year, numeric (4 digits)
yday            Day of the year, numeric (e.g., 299)
weekday         Day of the week, textual, full (e.g., "Friday")
month           Month, textual, full (e.g., "January")
0               Seconds since epoch (what time( ) returns)