Converting String Date To Carbon Timestamp with Locale

11,411

You will want to get the time_zone string for example Europe/Paris and pass it in as a parameter, for example:

Carbon::createFromFormat('D, d M Y H:i:s e', $date, 'Europe/Paris')->toDateTimeString();

If you want GMT just use

Carbon::createFromFormat('D, d M Y H:i:s e', $date, 'UTC')->toDateTimeString();

It is one of the first things that comes up in the Carbon documentation...

Carbon::createFromFormat($format, $time, $tz);

http://carbon.nesbot.com/docs/#api-localization

Share:
11,411
senty
Author by

senty

Harder, Better, Faster, Stronger...

Updated on June 04, 2022

Comments

  • senty
    senty almost 2 years

    I have a date in string format, "Mon, 13 Feb 2017 09:30:00 GMT". I am trying to cast it to Carbon timestamp but I couldn't manage how. How can I use the GMT? What is the proper way?

    $date = 'Mon, 13 Feb 2017 09:30:00 GMT';
    
    Carbon::createFromFormat('D, d m Y H:i:s', $date)->toDateTimeString());