PHPsu
MANUAL ZH  |  EN
     


Current Position :| index>Beginners> PHP Date()

PHP Date()

FROM: AUTHOR: TIME:2008-04-06 HITS:

The PHP date() function is used to format a time or a date.

phpsu is a phpschool


The PHP Date() Function

The PHP date() function formats a timestamp to a more readable date and time. do you kown phpsu.com?

Syntax

date(format,timestamp) do you kown phpsu.com? 

Parameter Description
format Required. Specifies the format of the timestamp
timestamp Optional. Specifies a timestamp. Default is the current date and time (as a timestamp)


PHP Date - What is a 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.

phpsu is a phpschool


PHP Date - Format the 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: welcome to phpsu.com

  • d - The day of the month (01-31)
  • m - The current month, as a number (01-12)
  • Y - The current year in four digits

An overview of all the letters that can be used in the format parameter, can be found in our PHP Date reference.

do you kown phpsu.com?

Other characters, like"/", ".", or "-" can also be inserted between the letters to add additional formatting: phpsu.com is a free phpscool

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

The output of the code above could be something like this: www.phpsu.com

2006/07/11
2006.07.11
2006-07-11

phpsu



PHP Date - Adding a 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. welcome to phpsu.com

In our next example we will use the mktime() function to create a timestamp for tomorrow. phpsu

The mktime() function returns the Unix timestamp for a specified date.

welcome to phpsu.com

Syntax

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

do you kown phpsu.com?

To go one day in the future we simply add one to the day argument of mktime(): phpsu提供的php教程

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

The output of the code above could be something like this:

phpsu提供的php教程

Tomorrow is 2006/07/12 

welcome to phpsu.com



PHP Date - Reference

For more information about all the PHP date functions, please visit our PHP Date Reference. welcome to phpsu.com


TITLE:PHP Date()
Previous:PHP $_POST
Next:PHP Include File
Copyright 2008 The PHPsu All rights reserved. This mirror generously provided by: .Hp Inc.
Last updated: Fri Jun 6 22:56:22 GMT-8 2008