time()函数是PHP中的一个内置函数,它返回自事件发生以来以秒为单位测量的当前时间 时间戳 。可以使用PHP中的date()函数将秒数转换为当前日期。
null
语法:
int time()
参数: 此函数不接受如上所示的任何参数。
返回值: 此函数用于返回自 Unix时代。
注: 所有程序的输出都与文章的写作日期相对应。
下面的程序演示了time()函数:
项目1: 下面的程序以秒为单位打印当前时间。
<?php // PHP program to demonstrate the use of current // time in seconds since Unix Epoch // variable to store the current time in seconds $currentTimeinSeconds = time(); // prints the current time in seconds echo $currentTimeinSeconds ; ?> |
输出:
1525376494
项目2: 下面的程序以日期格式打印当前时间。
<?php // PHP program to demonstrate the use of current // date since Unix Epoch // variable to store the current time in seconds $currentTimeinSeconds = time(); // converts the time in seconds to current date $currentDate = date ( 'Y-m-d' , $currentTimeinSeconds ); // prints the current date echo ( $currentDate ); ?> |
输出:
2018-05-03
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END