English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Date & Time Function Manual
The strftime() function formats the local time/date according to the region setting
strftimeThe function accepts a format string as a parameter and formats the local date and time according to the region setting/time..
strftime($format [, $timestamp])
Returns the string after formatting the given timestamp with the given format string. If no timestamp is provided, the current local time is used. The notation of month, day of the week, and other language-related strings are related to the current locale set by setlocale().
Serial number | Parameters and descriptions |
---|---|
1 | timestamp(必需) This is an integer value representing the Unix timestamp of the specified current time value. |
2 | format(可选) This is a string value indicating that you need to format the date/the format of time. Specify how to return the result:
|
PHP strftime()This function returns a string value representing the formatted time. You can usesetlocale()method changes the names of months and days of the week to other languages.
This function was originally introduced in PHP version5.3introduced in and can be used in all higher versions.
The following examples demonstratestrftime()Usage of the function-
<?php $date = strftime("%A %d %B %G"); $time = strftime("%T"); print("Date: ".$date."\n"); print("Time: ".$time); ?>Test and see‹/›
Output Result
Date: Wednesday 13 May 2020 Time: 06:28:07
Let's try this function by passing the timestamp parameter (and format)-
<?php $timestamp = mktime(7, 36, 45, 06, 25, 2017); $date = strftime("%A %d %B %G %T", $timestamp ); print("Date: ".$date."\n"); ?>Test and see‹/›
Output Result
Date: Sunday 25 June 2017 07:36:45
The following example prints the specific date's day of the week and month in Catalan-
<?php setlocale(LC_TIME, "ca_ES", "Catalan_Spain", "Catalan"); $date = strftime("%A %d %B %G %T"); print("Date: ".$date."\n"); ?>Test and see‹/›
Output Result
Date: Wednesday 13 maig 2020 08:14:19
<?php setlocale(LC_TIME, "en_US"); echo strftime("%b %d %Y %H:%M:%S", mktime(20, 0, 0, 12, 31, 2015)) . "\n"; echo gmstrftime("%b %d %Y %H:%M:%S", mktime(20, 0, 0, 12, 31, 2015)) . "\n"; ?>Test and see‹/›
This produces the following result-
Dec 31 2015 20:00:00 Dec 31 2015 20:00:00