English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Date & Time Functions Manual
The date() function formats a local date/time
Returns a string representing the integer timestamp formatted according to the given format string. If no timestamp is given, the local current time is used. In other words, timestamp is optional, and the default value is time().
date($format, $timestamp)
Number | Parameters and Description |
---|---|
1 | format (required) This is a format string that specifies the format you want to use for the output date string. |
2 | timestamp (optional) This is an integer value representing the timestamp of the required date |
The PHP date() function returns the current local time in the specified format/Date.
This function was first introduced in PHP version4introduced and can be used in all higher versions.
Try the following demonstration ofdate()Function Usage-
<?php $date = date("Y-m-d H:i:s"); print("Date: ",$date); ?>Test to see‹/›
Output Result
Date: 2020-07-30 13:51:04
You can escape characters in the date format as shown below-
<?php $date = date("jS F l \t"); print("Date: ",$date); ?>Test to see‹/›
Output Result
Date: 18the May Monday
The following examples demonstrate how to call it by passing a timestamp parameterdate()Function-
<?php $ts = 1022555568; $date = date("Y-m-d H:i:s, $ts); print($date); ?>Test to see‹/›
Output Result
2002-05-28 03:12:48
<?php date_default_timezone_set('UTC'); echo date("l"); echo "\n"; echo date('l dS of F Y h:i:s A'); ?>Test to see‹/›
This produces the following result-
Monday Monday 05the of December 2016 10:27:13 AM