How do I get the UTC date with Carbon if I use another timezone?
$timestamp = '2014-02-06 16:34:00'; Carbon::createFromFormat('Y-m-d H:i:s', $timestamp)->timezone('Europe/Stockholm');
I create with a Europe/Stockholm
timezone. How do I get the UTC date from that (2014-02-06 15:34)?
First, you set the timezone you initially have, so if you store your date in the database as UTC, then set the default timezone to UTC, then use ->setTimeZone('Valid/Timezone') to make the change from what you'v had to the new timezone.
UTC time in ISO-8601 is 14:10:11Z.
Times are expressed in UTC (Coordinated Universal Time), with a special UTC designator ("Z"). Times are expressed in local time, together with a time zone offset in hours and minutes. A time zone offset of "+hh:mm" indicates that the date/time uses a local time zone which is "hh" hours and "mm" minutes ahead of UTC.
You can set to session like below; Session::put('timezone', 'Your/TimeZone'); Enjoy your Code !
You can change the timezone with this:
$timestamp = '2014-02-06 16:34:00'; $date = Carbon::createFromFormat('Y-m-d H:i:s', $timestamp, 'Europe/Stockholm'); $date->setTimezone('UTC');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With