How can I change the timezone of the outputted date in Laravel 4?

前端 未结 1 1863
故里飘歌
故里飘歌 2020-12-22 00:39

I have a database with an entity table and a users table. The entity table has fields for created_at and updated_at. The

1条回答
  •  生来不讨喜
    2020-12-22 00:57

    You need to use the Carbon function copy() to keep the timezone unchanged on your object. Then you can just set the timezone to whatever you want and 'output' the result.

    $entity->created_at->copy()->tz(Auth::user()->timezone)->format('M j, Y \\a\\t g:i A');
    

    As for timezones - it is just PHP timezones.

    $tzlist = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
    

    0 讨论(0)
提交回复
热议问题