An older article, may still apply https://www.mattsimpson.ca/2014/03/31/displaying-dates-using-user-selected-timezones-in-laravel-4
Displaying dates accordingly to each timezone.
So let's say I create and store in a database a cupon for a discount that is available starting from tomorrow 4pm LOCALE TIME (GMT-7), this data is stored in a "starts_at" field in UTC format so it would be 11 pm in UTC format.
So if it's next day 1pm in my locale (GMT-7) I want it to say "this coupon will be available in 3 hours" instead of 10 hours (which would be 3 hours + 7 difference from utc)
How to achieve this?
Need it this way because people might see it from different timezones, and I want it to tell them how long for it to start (or how long time left, etc) according to their timezone.
You'll need to store the users timezone in their profile or users table. Then when outputting/displaying dates, just format it using the users timezone. created_at and updated_at are automatically converted to carbon instances, which makes this easier. If you have other dates that you're using, add them to the protected $dates array on the model and laravel will convert them to carbon instance too and then you can use carbons setTimezone() to change the date/time to the users timezone.
Then you'd just:
$userTimezone = 'America/Vancouver';
echo $your_db_result->created_at->setTimezone($userTimezone);
If you are accepting date/times from user input, that will be in their local timezone. When storing those dates, you'll need to convert back to UTC before storing in the db using $user_supplied_date->setTimezone('UTC').
Please or to participate in this conversation.