你好,我需要从变量time和date中删除句点和连字符。
这是我的代码:
$todaydate = date('Y-m-d') ."'n";
$time_utc=mktime(date('G'),date('i'),date('s'));
$NowisTime=date('G:i:s',$time_utc);
这将返回如下内容:
$todaydate = 2011-06-03
$NowisTime = 14:20:30
我需要实现的是:
$todaydate = 20110603
$NowisTime = 142030
我该怎么做?
感谢
您可以执行以下操作:
$todaydate = date('Ymd');
$time_utc=mktime(date('G'),date('i'),date('s'));
$NowisTime=date('Gis',$time_utc);
为什么不使用
$todaydate = date('Ymd');
处理字符串时可以使用的可能性
preg_replace('/-|:/', null, $date);
在date()
调用中根本不要键入连字符和句点!
在您的情况下,我只使用PHP的DateTime类:
$dateTime= new DateTime('now');
var_dump(array(
'currentDate' => $dateTime->format('Ymd'),
'currentTime' => $dateTime->format('Gis'),
));