Support the ongoing development of Laravel.io →
Configuration Database
Last updated 1 year ago.
0

Check this out:

http://stackoverflow.com/questions/17396194/what-is-the-best-w...

Then change accepted code as it's a bit wrong:

// Let's say we have:
// DateTime from db: 2014-04-30 14:30:00 UTC
// User timezone 'Europe/London'

// This is going to return Carbon object with datetime in UTC from your db but applies given timezone instead.
if (is_numeric($value)) {
     return Carbon::createFromTimestamp($value, $tz);
}
// returns 2014-04-30 14:30:00 'Europe/London'


// so what you need is to retrieve your datetime in UTC and then convert it to your timezone
if (is_numeric($value)) {
     return Carbon::createFromTimestamp($value)->setTimezone($tz);
}
// returns correctly converted datetime: 2014-04-30 15:30:00 'Europe/London'

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

jani8x jani8x Joined 30 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.