PHP使用GETDATE获取当前日期时间作为一个关联数组的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了PHP使用GETDATE获取当前日期时间作为一个关联数组的方法。分享给大家供大家参考。具体分析如下:

PHP GETDATE函数是用来获得当前的日期和时间,从操作系统或一个关联数组转换成UNIX风格的日期整数。

语法格式如下

array getdate ();
array getdate (integer $Time);

参数如下:
Arguments

$Time
The number of seconds since midnight before January 1, 1970. (UNIX style.)
Default
The default is the current date and time from the operating system.)

The return value is an associative array containing:

mon The month of the year as a number (1..12)
mday The day of the month (1..31)
year The year (4 digits)
hours The hour of the day (0..23)
minutes The minutes of the hour (0..59)
seconds The seconds of the minute (0..59)
month The month of the year as a word (January..December)
yday The day of the year (0..365)
wday The day of the week as a number (0..6)
weekday The day of the week as a word (Sunday..Saturday)
0 Seconds since midnight before January 1, 1970

下面是一个使用范例:

<?php
$Now = getdate();
foreach ($Now as $Key => $Value) {
 echo "$Key => $Value\n";
}
?>

输出结果如下:

seconds => 59
minutes => 14
hours => 7
mday => 26
wday => 6
mon => 12
year => 2009
yday => 359
weekday => Saturday
month => December
0 => 1261811699

希望本文所述对大家的php程序设计有所帮助。

相关文章

php 中文字符入库或显示乱码问题的解决方法

大家以后在编写过程中, 一定要记得定义字符类型。mysql_query("set names 'gbk'") 解决的方法就这么简单。 今天做了一个数据库查询,放出代码。 复制代码 代码如...

解决安装WampServer时提示缺少msvcr110.dll文件的问题

解决安装WampServer时提示缺少msvcr110.dll文件的问题

今天开始学习PHP,对于初学者来说,我们一定希望从简单的开始,所以,从集成环境非常好的WampServer的安装开始. 1、下载WampServer安装程序,安装完毕后会出现一个错误.如...

php获取根域名方法汇总

本文实例汇总了php获取根域名方法,分享给大家供大家参考。具体实现方法如下: 如果你只简单获取当前访问你页面的域名,我们只需要使用php中的函数HTTP_HOST就可以搞定了,如果是提取...

php中用date函数获取当前时间有误的解决办法

初学PHP做网站,想在页面上获得当前时间,学过编程的人都知道用时间函数date(),先用这个函数格式化一个本地时间/日期,先写个测试代码吧,结果输出时间比实际时间少了8小时,这是什么原因...

php实现插入排序

<?php /** * 插入排序 * @param Array $a 无序集合 * @return Array 有序集合 */ function insertS...