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, with a default value of time().
date($format, $timestamp)
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/date in the specified format.
This function was initially introduced in PHP version 4 and can be used in all higher versions.
Try the following demonstrationdate()Usage of Function-
<?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 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 example calls by passing the 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