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

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

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


<?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']); // 参数:时,分,秒,月,日,年

<?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;

strtotime('2015-10-10');

【热门文章】
【热门文章】