分析php的时间戳转换!

来源:互联网 发布:mac的cmd在哪里 编辑:程序博客网 时间:2024/06/08 05:38

说到php的时间戳转换非常强大便捷:

  1. 1. UNIX时间戳转换为日期用函数: date()
  2. 一般形式:date('Y-m-d H:i:s', 1156219870);
  3. 2. 日期转换为UNIX时间戳用函数:strtotime()
  4. 一般形式:strtotime('2010-03-24 08:15:42');
以上两个函数就可以转换php中的时间戳和时间格式。

怎么灵活的运用?

这里举我项目中的例子:

$todaystart = strtotime(date("y-m-d", $time) . ' 00:00:00');$todayover = strtotime(date("y-m-d", $time) . ' 23:59:59');
我们利用time()函数取得当前时间戳保存在$time变量中,用date()函数还原日期拼接时间在用strtotime()函数将日期格式转化成
时间戳。
就是取当天开始和结束的时间戳。
$moncent=date('Y-m-01', strtotime(date("Y-m-d")));$monthstart=strtotime(date('Y-m-01', strtotime(date("Y-m-d"))));$monthover=strtotime(date('Y-m-d', strtotime("$moncent +1 month -1 day")));
取得当月起始时间和当月结束时间戳。



0 0
原创粉丝点击