Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get UTC from another timezone with Carbon

Tags:

php

php-carbon

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)?

like image 749
Marwelln Avatar asked Feb 06 '14 15:02

Marwelln


People also ask

How do I change the timezone on my carbon?

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.

What is UTC time now in 24 hour format?

UTC time in ISO-8601 is 14:10:11Z.

How do you format time in UTC?

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.

How do I get current time zone in laravel?

You can set to session like below; Session::put('timezone', 'Your/TimeZone'); Enjoy your Code !


1 Answers

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'); 
like image 77
Marwelln Avatar answered Sep 19 '22 22:09

Marwelln