I have date format like '25 May 2016 10:45:53:567'.
I want to convert into the time stamp.
strtotime
function returns empty.
$date = '25 May 2016 10:45:53:567';
echo strtotime($date);
// returns empty
When I removed the milliseconds, it's working.
$date = '25 May 2016 10:45:53';
echo strtotime($date);
// returns 1464153353
Please sort out my issue. Thanks in advance.
Use DateTime
:
$date = DateTime::createFromFormat('d M Y H:i:s:u', '25 May 2016 10:45:53:000');
echo $date->getTimestamp();
// 1464165953
// With microseconds
echo $date->getTimestamp().'.'.$date->format('u');
// 1464165953.000000
Split string:
$date = '25 May 2016 10:45:53:001';
preg_match('/^(.+):(\d+)$/i', $date, $matches);
echo 'timestamp: ' . strtotime($matches[1]) . PHP_EOL;
echo 'milliseconds: ' . $matches[2] . PHP_EOL;
// timestamp: 1464162353
// milliseconds: 001
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With