您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
三六零分类信息网 > 河池分类信息网,免费分类信息发布

php怎么获取时间戳

2025/6/11 3:27:27发布7次查看
php获取时间戳的方法:可以利用time()函数或strtotime()函数来获取。time()函数返回一个包含当前时间的unix时间戳的整数。strtotime()函数将任何字符串的日期时间描述解析为unix时间戳。
time() 函数返回自 unix 纪元(january 1 1970 00:00:00 gmt)起的当前时间的秒数。返回一个包含当前时间的 unix 时间戳的整数。
(推荐教程:php图文教程)
代码实现:
<?php$t=time();echo($t . "<br>");echo(date("y-m-d",$t));?>
strtotime() 函数将任何字符串的日期时间描述解析为 unix 时间戳(自 january 1 1970 00:00:00 gmt 起的秒数)。
语法:
int strtotime ( string $time [, int $now = time() ] )
(视频教程推荐:php视频教程)
参数:
time 必需。规定日期/时间字符串。
now 可选。规定用来计算返回值的时间戳。如果省略该参数,则使用当前时间。
代码实现:
<?php// 设置时区date_default_timezone_set("prc");$time = strtotime("2018-01-18 08:08:08"); // 将指定日期转成时间戳 // 打印当前时间 php_eol 换行符,兼容不同系统echo $time, php_eol; // 更多实例echo strtotime("now"), php_eol;echo strtotime("now"), php_eol;echo strtotime("10 september 2000"), php_eol;echo strtotime("+1 day"), php_eol;echo strtotime("+1 week"), php_eol;echo strtotime("+1 week 2 days 4 hours 2 seconds"), php_eol;echo strtotime("next thursday"), php_eol;echo strtotime("last monday"), php_eol;?>
以上就是php怎么获取时间戳的详细内容。
河池分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product