4

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());
Machavity
  • 30,841
  • 27
  • 92
  • 100
senty
  • 12,385
  • 28
  • 130
  • 260

1 Answers1

5

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

Jethro Hazelhurst
  • 3,230
  • 7
  • 38
  • 80