Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 php时间转换unix时间戳实例

php时间转换unix时间戳实例

发布时间:2018-02-14   编辑:www.jquerycn.cn
本文介绍了php编程中unix时间戳转换的小例子,有关php时间转换、php时间戳的实例代码,有需要的朋友参考下。

第一部分,php 时间转换unix 时间戳实现代码。
 

复制代码 代码示例:
<?php
date_default_timezone_set('asia/chongqing');
$time1 = "2006-04-16 08:40:54";
$time2 = strtotime($time1);
echo $time2;
echo date('y-m-d h:i:s',$time2);
//php unix时间戳转换代码
?>

第二部分,php strtotime 函数unix时间戳
int strtotime ( string time [, int now]) 本函数预期接受一个包含英文日期格式的字符串并尝试将其解析为 unix 时间戳。

如果 time 的格式是绝对时间则 now 参数不起作用。\
如果 time 的格式是相对时间则其所相对的时间由 now 提供,或如果未提供 now 参数时用当前时间。
失败时返回 -1。

例子:
 

复制代码 代码示例:
<?php
echo strtotime ("now"), "\n";
echo strtotime ("10 september 2000"), "\n";
echo strtotime ("+1 day"), "\n";
echo strtotime ("+1 week"), "\n";
echo strtotime ("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime ("next thursday"), "\n";
echo strtotime ("last monday"), "\n";
 
$str = 'not good';
if (($timestamp = strtotime($str)) === -1) {
echo "the string ($str) is bogus";
} else {
echo "$str == ". date('l ds of f y h:i:s a',$timestamp);
} //by www.jbxue.com
?>

这个效果和用mktime()是一样的。

您可能感兴趣的文章:
php 创建以unix时间戳命名的文件夹
php时间转换unix时间戳实例
php时间函数strtotime的深入理解
php时间戳转换
php 时间数据转换为时间戳代码
python时间戳是什么
php与Mysql日期时间(UNIX时间戳、格式化日期)转换的方法
php 获取今日、昨日、上周、本月的起始与结束时间戳
php 时间戳函数总结与示例
PHP unixtojd() 函数

关键词: php时间戳  时间戳转换  时间转换   
[关闭]