I have this date time string vendredi 11 février 2022 à 20:19:56 heure normale d’Europe centrale
stored in my database.
Now I'm trying to convert it back to its equivalent in English UTC date time.
In order to process it, I tried strtotime
:
$datetime = 'vendredi 11 février 2022 à 20:19:56 heure normale d’Europe centrale';
$tsparis = strtotime($datetime . ' Europe/Paris');
var_dump($tsparis);
This shows bool(false)
. How can I parse this string back to a timestamp.
CodePudding user response:
You can use IntlDateFormatter to parse dates from strings as well as format them to strings.
In this case, passing a locale of 'fr_FR', and date and time formats of "full" should be enough:
$datetime = 'vendredi 11 février 2022 à 20:19:56 heure normale d’Europe centrale';
$parser = new IntlDateFormatter(
'fr_FR',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL
);
$tsparis = $parser->parse($datetime);
var_dump($tsparis);
Gives int(1644607196)
; see online demo
This gives you a standard Unix timestamp, which you can process using whatever you want to generate a new output.