站长资讯网
最全最丰富的资讯网站

php中怎么将时间转换为时间戳

php中怎么将时间转换为时间戳

PHP 提供了函数可以方便的将各种形式的日期转换为时间戳,该类函数主要是:

strtotime():将任何英文文本的日期时间描述解析为时间戳。

mktime():从日期取得时间戳。

strtotime()

strtotime() 函数用于将英文文本字符串表示的日期转换为时间戳,为 date() 的反函数,成功返回时间戳,否则返回 FALSE 。

语法:

int strtotime ( string time [, int now] )

示例:

<?php echo strtotime("2009-10-21 16:00:10"); //输出 1256112010 echo strtotime("10 September 2008"); //输出 1220976000 echo strtotime("+1 day"), "<br />"; //输出明天此时的时间戳 ?>

mktime()

mktime() 函数用于从日期取得时间戳,成功返回时间戳,否则返回 FALSE 。

语法:

int mktime(时, 分, 秒, 月, 日, 年)

示例:

<?php echo mktime(21, 50, 55, 07, 14, 2010); //输出“1279115455” ?>

赞(0)
分享到: 更多 (0)

网站地图   沪ICP备18035694号-2    沪公网安备31011702889846号