Change returning datetime Time zone to recalculate with user Time zone – Laravel

Use the code below to set time zone in Laravel.

<!-- wp:loos-hcb/code-block -->
<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code></code></pre></div>
<!-- /wp:loos-hcb/code-block -->

Then change the returning time zone to recalculate with a user’s time zone in Laravel.

// on a date column
$user->created_at->timezone('Asia/Kolkata')->toDateTimeString()

// Directly on a Carbon instance 
Carbon\Carbon::parse('2018-01-22 04:09:31')->timezone('Asia/Kolkata')->toDateTimeString()


Check out these Links
Credit: https://laracasts.com/discuss/channels/laravel/change-date-timezone-in-laravel-project-while-fetching-date?page=1&replyId=576247
Actual Article: https://qcode.in/managing-users-timezone-in-laravel-app/

Laravel allows you to dynamically set timezone using the package given below.

Look up this package below, you can Automatically Set a Local Timezone for Users:
https://github.com/jamesmills/laravel-timezone
Credit: https://laravel-news.com/laravel-timezone

Leave a Comment