Easy Tutorial
❮ Php Preg_Quote Func Simplexml Addattribute ❯

PHP date() Function

PHP Date/Time Reference Manual

Example

Formats the local date and time and returns the formatted date string:

<?php
// Set timezone
date_default_timezone_set("PRC");

// Print current time  PHP_EOL for line break, compatible with different systems
echo date("Y-m-d H:i:s")  . PHP_EOL;
echo date("Y年m月d日H点i分s秒")  . PHP_EOL;
// Specify time
$time = strtotime("2018-01-18 08:08:08");  // Convert specified date to timestamp
echo date("Y-m-d H:i:s", $time)  . PHP_EOL;
?>

Output is as follows:

2018-01-31 22:09:35
2018年01月31日22点09分35秒
2018-01-18 08:08:08

Definition and Usage

The date() function formats the local date and time and returns the formatted date string.

Syntax

Returns a string generated according to the given format string using the integer timestamp. If no timestamp is given, it uses the current local time. In other words, the timestamp is optional and defaults to the value of time().

| Parameter | Description | | --- | --- | Required. Specifies the format of the output date string. The following characters can be used:

Additionally, the following predefined constants are available (since PHP 5.1.0):

Technical Details

Return Value: Returns a formatted date string on success, or issues an E_WARNING and returns FALSE on failure.
PHP Version: 4+
--- ---
Changelog: PHP 5.1.0: Added E_STRICT and E_NOTICE timezone errors. Valid range for timestamps is from Friday, 13 December 1901 20:45:54 GMT to Tuesday, 19 January 2038 03:14:07 GMT. In versions prior to 5.1.0, on some systems (such as Windows), timestamps were limited from 01-01-1970 to 19-01-2038. <br>PHP 5.1.1: Added standard date/time format constants for specifying the format parameter.
--- ---
❮ Php Preg_Quote Func Simplexml Addattribute ❯