Skip to content
Advertisement

Convert timestamp with dots in PHP (“yyyy.mm.dd hh:nn:ss.zzz”)

I’m trying to convert strings with hungarian datetime format, but no success because of the dot-separators:

JavaScript

Isn’t it possible without “string-replace” like this:
strtotime(preg_replace("/([0-9]{4}).([0-9]{2}).([0-9]{2})/",'${1}-${2}-${3}',$xml->delivery_time)) ?

(I’m new to PHP 5 and I’m shocked it can not simply convert a common date format. Searched 200+ results, wasted 4+ hours … no success.)

Advertisement

Answer

This solution will also work for PHP versions below 7.3

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement