PHP | idate()函数

idate()函数是PHP中的一个内置函数,用于将本地时间/日期格式化为整数。$format和$timestamp作为参数发送给idate()函数,它使用给定的时间戳返回根据指定格式格式化的整数。与函数date()不同,idate()只接受format参数中的一个字符。

null

语法:

int idate( $format, $timestamp )

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

  • $格式: 它是一个强制参数,用于指定结果的格式。format参数可以具有以下值:
    • B–斯沃琪节拍/互联网时间
    • d–月日
    • 小时(12小时格式)
    • 小时(24小时格式)
    • i–分钟
    • I–如果DST(夏令时)被激活,则返回1,否则返回0
    • L–闰年返回1,否则返回0
    • m–月数
    • s–秒
    • t–当月的天数
    • U–自Unix时代以来的秒数(1970年1月1日00:00:00 GMT)
    • w–一周中的某一天(周日=0)
    • W–ISO-8601年的周数(周从周一开始)
    • y–年份(1或2位数)
    • Y–年份(4位数字)
    • z–一年中的某一天
    • Z–时区偏移量(以秒为单位)
  • $timestamp: 它是一个可选参数,用于指定表示要格式化的日期/时间的Unix时间戳。

返回值: 它使用给定的时间戳,根据指定的格式返回一个整数值。

例外情况:

  • 如果时区无效,idate()函数会在每次调用日期/时间时抛出E_通知。
  • 如果使用系统设置或TZ环境变量,idate()函数将抛出E_STRICT或E_警告消息。

下面的程序演示了PHP中的idate()函数:

项目1:

<?php
// Formatting local date/time as Year
echo idate( "Y" ) . "<br>" ;
// Formatting local date/time as Hour(24 hr format)
echo idate( "H" ) . "<br>" ;
// Formatting local date/time as Minutes
echo idate( "i" ) . "<br>" ;
// Formatting local date/time as day of the year
echo idate( "z" ) . "<br>" ;
?>


输出:

20181122238

项目2:

<?php
// Parsing English textual datetime description into a Unix timestamp
$timestamp = strtotime ( '24th August 2018' );
// Formatting local date/time as Year
echo idate( 'Y' , $timestamp );
?>


输出:

2018

相关文章:

参考: http://php.net/manual/en/function.idate.php

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