109*_*793 4 php datetime unix-timestamp
我有一个存储时间的数据库.我用PHP插入它
date( 'Y-m-d H:i:s');
Run Code Online (Sandbox Code Playgroud)
然后我使用此函数将其转换为PHP中的unix时间戳
function convert_datetime($str)
{
list($date, $time) = explode(' ', $str);
list($year, $month, $day) = explode('-', $date);
list($hour, $minute, $second) = explode(':', $time);
$timestamp = mktime($hour, $minute, $second, $month, $day, $year);
return $timestamp;
}
Run Code Online (Sandbox Code Playgroud)
我现在需要做的是将这个时间戳转换为这种格式的日期和时间:yyyymmddhhmmss(没有任何连字符,破折号,冒号等).
有没有人有任何想法?
Sar*_*raz 16
你可以使用strtotime和date功能:
echo date('Ymdhis', strtotime($date));
Run Code Online (Sandbox Code Playgroud)