伙计们,我希望将这种类型的datetime-stamp转换为php中的unix / epoch时间
2019-08-10D00:00:03.712125000
有什么想法吗?
答案 0 :(得分:3)
PHP DateTime只能使用小数点后的4位数字。因此,您可以选择一开始就忽略该部分,然后(如果适用)将其附加到最终时间戳。但是请记住,这可能会引起问题。
$string = "2019-08-10D00:00:03.712125000";
$parts = explode(".", $string);
$microseconds = $parts[1];
$date = DateTime::createFromFormat("Y-m-d\DH:i:s", $parts[0]);
$timestamp = $date->getTimestamp();
// If you want to round it to 4 decimal places
// $microseconds = ltrim(round("0.".$microseconds, 4), "0.");
// If you want to append the microseconds back for whichever reason
// $timestamp .= ".".$microseconds;
echo $timestamp;