Check this out:
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'
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community