本文介绍了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; // www.jbxue.com 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"), " "; echo strtotime ("10 september 2000"), " "; echo strtotime ("+1 day"), " "; echo strtotime ("+1 week"), " "; echo strtotime ("+1 week 2 days 4 hours 2 seconds"), " "; echo strtotime ("next thursday"), " "; echo strtotime ("last monday"), " "; // www.jbxue.com $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()是一样的。
版权声明
1.本站大部分下载资源收集于网络,不保证其完整性以及安全性,请下载后自行测试。
2.本站资源仅供学习和交流使用,版权归资源原作者所有,请在下载后24小时之内自觉删除。
3.若作商业用途,请购买正版,由于未及时购买和付费发生的侵权行为,与本站无关。
4.若内容涉及侵权或违法信息,请联系本站管理员进行下架处理,邮箱ganice520@163.com(本站不支持其他投诉反馈渠道,谢谢合作)
- 上一篇: 陌屿云PLUS版V8.01开源版本 PHP在线加密系统源码
- 下一篇: PHP获取网页内容的几种方法
发表评论