>  기사  >  백엔드 개발  >  怎样把类似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으로 문의하세요.
이전 기사:PDO::query怎么理解다음 기사:MySql字段加1出错