首頁  >  文章  >  後端開發  >  怎样把类似2015年1月1号这样的数据转化为时间戳 SegmentFault

怎样把类似2015年1月1号这样的数据转化为时间戳 SegmentFault

WBOY
WBOY原創
2016-06-06 20:23:141264瀏覽

php中,怎样把类似2015年1月1号这样的数据转化为时间戳,日期可能是一位,也可能是两位,例如2015年11月4号,2015年4月11号,等等。

回复内容:

php中,怎样把类似2015年1月1号这样的数据转化为时间戳,日期可能是一位,也可能是两位,例如2015年11月4号,2015年4月11号,等等。

<code><?php /**
 * Created by PhpStorm.
 * User: Bruce
 * Date: 15/12/3
 * Time: 下午2:06
 */
$arr = date_parse_from_format ( "Y年m月d日" , "2015年10月12日" );
$timestamp = mktime(0,0,0,$arr['month'],$arr['day'],$arr['year']);
echo $timestamp;</code></code>

<code><?php header('Content-Type: text/plain;charset=utf-8');
$arr = date_parse_from_format('Y年m月d日', '2015年10月1日');
//下面3个输出都是1443628800
echo strtotime('2015-10-1')."\n";
echo strtotime($arr['year'].'-'.$arr['month'].'-'.$arr['day'])."\n";
echo mktime(0, 0, 0, $arr['month'], $arr['day'], $arr['year']); // 参数:时,分,秒,月,日,年</code></code>

strtotime('2015-10-10');

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn