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 that represents the integer timestamp in 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)
Serial Number | Parameters and Description |
---|---|
1 | format (required) This is a format string that specifies the format of the date string you want to output. |
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 originally 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: 18th May Monday
The following examples show 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 05th of December 2016 10:27:13 AM