<?php
// The corresponding time stamp of the current time stamp GMT time,Formatted as Year-moon-day Hour:minute:Second
echo gmdate('Y-m-d H:i:s');
?>
Output example:
2025-05-24 06:30:00
Returning here is the current date and time of Greenwich time.
gmdate will only return the number date and time part, and the month and week will not be converted into language text. It does not change the language according to the system's locale settings.
For example:
<?php
echo gmdate('l, F j, Y'); // The output is similar:Saturday, May 24, 2025
?>
The output is always in English by Saturday and May .
In order to output the date format of the local language, the localized locale is usually set with setlocale() , and then the localized date string is output with strftime() .
However, strftime() uses the server local time. To combine the GMT time obtained by gmdate() , you can use gmstrftime() (available from PHP 8.1), or manually adjust the timestamp.
Example:
<?php
// Set the locale to Chinese(China)
setlocale(LC_TIME, 'zh_CN.UTF-8');
// use gmstrftime Output GMT time的本地化day期
echo gmstrftime('%A %e %B %Y', time());
?>
This will output the Chinese day of week, month, etc. For example:
Saturday 24 五moon 2025
Note: gmstrftime() may not be available in older PHP versions, consider using strftime() and manually converting the time to local time.
If the server does not have the required language pack installed, or if you want to control the language more flexibly, you can manually map the English month and week to the target language.
Sample code:
<?php
// Get GMT time
$timestamp = time();
// 英文星期和moon份
$week_en = gmdate('l', $timestamp);
$month_en = gmdate('F', $timestamp);
// 中文星期和moon份映射
$week_map = [
'Monday' => 'Monday',
'Tuesday' => 'Tuesday',
'Wednesday' => 'Wednesday',
'Thursday' => 'Thursday',
'Friday' => 'Friday',
'Saturday' => 'Saturday',
'Sunday' => '星期day',
];
$month_map = [
'January' => '一moon',
'February' => '二moon',
'March' => '三moon',
'April' => '四moon',
'May' => '五moon',
'June' => '六moon',
'July' => '七moon',
'August' => '八moon',
'September' => '九moon',
'October' => '十moon',
'November' => '十一moon',
'December' => '十二moon',
];
// 拼接Output中文格式day期
$day = gmdate('j', $timestamp);
$year = gmdate('Y', $timestamp);
echo $week_map[$week_en] . " " . $day . " " . $month_map[$month_en] . " " . $year;
?>
Output:
Saturday 24 五moon 2025
gmdate() is used to format digital date time based on GMT time.
It does not support text output in multi-language environments.
To implement multilingual display, you can use setlocale() + gmstrftime() or map date text by yourself.
Choose the appropriate method based on the actual server environment and PHP version.
<?php
// Setting up the locale
setlocale(LC_TIME, 'zh_CN.UTF-8');
// Get当前 GMT time戳
$timestamp = time();
// use gmstrftime Output本地化day期(GMT time)
echo gmstrftime('%A %e %B %Y', $timestamp);
// or manually map(See the example above)
?>