简体   繁体   中英

Php how to convert a date time string in French back to its equivalent in English UTC

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM