PHP()函数

gmstrftime()函数是PHP中的内置函数,用于根据本地设置格式化GMT/UTC时间/日期。PHP中的gmstrftime()函数的行为与strftime()相同,只是gmstrftime()函数返回的时间是格林威治标准时间(GMT)。这个 $format $timezone 作为参数发送到gmstrftime()函数,并返回根据使用给定时间戳指定的格式格式化的字符串。

null

语法:

string gmstrftime( $format, $timestamp )

参数: 该函数接受两个参数,如下所述:

  • $格式: 它是一个强制参数,用于指定结果的格式。
  • $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

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享