·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> php网站开发 >> php时间转换unix时间戳

php时间转换unix时间戳

作者:佚名      php网站开发编辑:admin      更新时间:2022-07-23
php时间转换unix时间戳本文介绍了php编程中unix时间戳转换的小例子,有关php时间转换、php时间戳的实例代码,有需要的朋友参考下。

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

复制代码代码示例:<?phpdate_default_timezone_set('asia/chongqing');$time1 = "2006-04-16 08:40:54";$time2 =strtotime($time1);echo $time2; // www.jbxue.comecho 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。

例子:

复制代码代码示例:<?phpecho 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"; // 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()是一样的。

您可能感兴趣的文章:
  • php 创建以unix时间戳命名的文件夹
  • PHP函数microtime()时间戳的定义与用法
  • php取得某段时间区间的时间戳的代码
  • php 时间戳函数总结与示例
  • php 当前时间、时间戳的获取方法汇总
  • php时间戳应用举例
  • php时间转换Unix时间戳的代码
  • 学习php中时间戳和日期格式的转换