当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > PHP Date

PHP
PHP 安全邮件
MySQL 介绍
连接 MySQL
创建 MySQL
MySQL 插入记录
MySQL 选择记录
MySQL Where
MySQL Order By
MySQL 记录更新
MySQL 删除记录
PHP ODBC
XML Expat Parser
XML SimpleXML
PHP 数组参考
PHP Calendar
PHP Date
PHP Directory
PHP Filesystem
PHP FTP
PHP HTTP

PHP Date


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 1523 ::
收藏到网摘: n/a

The PHP date() function is used to format a time or a date.
PHP date()函数的作用是定义一个时间[time]或日期[date]。


The PHP Date() Function
PHP Date()函数

The PHP date() function formats a timestamp to a more readable date and time.
PHP date()函数的作用是给日期和时间定义一个“timestamp”。

Syntax
语法

date(format,timestamp)

 

Parameter
参数
Description
描述
format Required. Specifies the format of the timestamp
必要参数。指定timestamp的格式(format of the timestamp)
timestamp Optional. Specifies a timestamp. Default is the current date and time (as a timestamp)
可选参数。指定一个timestamp。默认值是当前日期和时间(以此作为timestamp)

 


PHP Date - What is a Timestamp?
PHP 日期 – 究竟什么是Timestamp呢?

A timestamp is the number of seconds since January 1, 1970 at 00:00:00 GMT. This is also known as the Unix Timestamp.
Timestamp:从1970年1月1日起格林尼治标准时间(GMT)规定了一秒钟的标准当量,timestamp就是指以这个为标准的总的秒数。这类似于Unix Timestamp。


PHP Date - Format the Date
PHP 日期date()—— 定义日期

The first parameter in the date() function specifies how to format the date/time. It uses letters to represent date and time formats. Here are some of the letters that can be used:
Date()函数中的第一个参数定义了日期/时间的格式。它是用字母来表示日期/时间的格式。下面对这些字母作具体说明:

  • d - The day of the month (01-31)
    d – 每月包含的天数(01-31)
  • m - The current month, as a number (01-12)
    m – 当前月份,用数字(01-12)表示
  • Y - The current year in four digits
    Y – 当前的年份,用四位数字表示

An overview of all the letters that can be used in the format parameter, can be found in our PHP Date reference.
关于日期/时间格式的所有参数可以参阅我们的PHP Date 参数

Other characters, like"/", ".", or "-" can also be inserted between the letters to add additional formatting:
其他字符,如:"/" "." "-" 也可以插入上述的日期/时间格式字母之间来定义显示格式,具体如下:

<?php
echo date("Y/m/d");
echo "<br />";
echo date("Y.m.d");
echo "<br />";
echo date("Y-m-d");
?>

The output of the code above could be something like this:
上述代码将输出下面的结果:

2006/07/11
2006.07.11
2006-07-11

 


PHP Date - Adding a Timestamp
PHP 日期(Date)- 添加一个Timestamp

The second parameter in the date() function specifies a timestamp. This parameter is optional. If you do not supply a timestamp, the current time will be used.
Date()函数中的第二个参数指定了一个timestamp。这个参数是一个可选(optional)参数。如果你不指定这个参数,那么将默认使用当前时间。

In our next next example we will use the mktime() function to create a timestamp for tomorrow.
在下面的例子中,我们将使用mktime()函数为明天创建一个timestamp。

The mktime() function returns the Unix timestamp for a specified date.
Mktime()函数为指定的日期返回了Unix timestamp。

Syntax
语法

mktime(hour,minute,second,month,day,year,is_dst)

To go one day in the future we simply add one to the day argument of mktime():
我们通过给mktime()中的day自变量(argument)加入一个timestamp直接前进到将来的某一天,具体如下:

<?php
$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
echo "Tomorrow is ".date("Y/m/d/", $tomorrow);
?>

The output of the code above could be something like this:
上述代码将输出下面的结果:

Tomorrow is 2006/07/12

 


PHP Date - Reference
PHP Date – 参数

For more information about all the PHP date functions, please visit our PHP Date Reference.
具体的PHP日期参数请访问我们的PHP Date 参数

评论 (0) All

登陆 | 还没注册?