gmstrftime()函數是PHP中的內置函數,用於根據本地設置格式化GMT /UTC時間/日期。 PHP中的gmstrftime()函數的行為與strftime()相同,隻是gmstrftime()函數返回的時間為格林威治標準時間(GMT)。 $format和$timezone作為參數發送到gmstrftime()函數,並返回根據使用給定時間戳記指定的格式設置格式的字符串。
用法:
string gmstrftime( $format, $timestamp )
參數:該函數接受上述和以下描述的兩個參數:
- $format:它是必填參數,用於指定結果格式。
- $timestamp:它是一個可選參數,用於指定表示要格式化的日期和/或時間的UNIX時間戳。
返回值:此函數根據給定時間戳記指定的格式返回格式化的字符串。
異常:
- 月份,工作日名稱和其他與語言相關的字符串會遵循通過setlocale()函數設置的當前語言環境。
- 如果在gmstrftime()函數中未提供時間戳,則默認為time()的值,或者換句話說,為當前本地時間。
以下示例程序旨在說明PHP中的gmstrftime()函數:
程序1:
<?php
// Using gmstrftime() function to return the GMT time
echo(gmstrftime("%B %d %Y, %X %Z", mktime(14, 0, 0, 8, 31, 18)));
?>
輸出:
August 31 2018, 14:00:00 GMT
程序2:
<?php
// Using gmstrftime() function to return the GMT time
setlocale(LC_ALL, 'en_US');
echo(gmstrftime("%B %d %Y, %X %Z"));
?>
輸出:
August 31 2018, 09:55:21 GMT
相關文章:
參考: http://php.net/manual/en/function.gmstrftime.php
相關用法
- p5.js str()用法及代碼示例
- CSS var()用法及代碼示例
- p5.js pow()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- p5.js value()用法及代碼示例
- p5.js day()用法及代碼示例
- PHP next()用法及代碼示例
- d3.js d3.map.has()用法及代碼示例
- p5.js sq()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- PHP pow( )用法及代碼示例
- p5.js hex()用法及代碼示例
注:本文由純淨天空篩選整理自Shubrodeep Banerjee大神的英文原創作品 PHP | gmstrftime() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。