2012-01-02 00:00:01
我想最后截取的是‘201201’
我应该怎么做
------解决方案--------------------
- PHP code
"echo date('Ym', time());"
------解决方案--------------------
- PHP code
function get_cut($str, $num = 6){
$str = str_replace('-', '', $str);
preg_match('/\d{' . $num . '}/', $str, $arr);
return $arr[0];
}
echo get_cut('2012-03-14'); // 201203
echo get_cut('2012-03-14', 8); // 20120314
------解决方案--------------------
$s='2012-03-14';
echo date("Ym",strtotime($s));