Learn how to manage timezones in your Laravel Apps

In this video, Ben Holmen teaches us how to manage timezones in your Laravel apps. Some of the highlights include:

  • Store all dates and times in UTC
  • Define a default application Timezone
  • Use Carbon macros for conversions
  • Either automatically or manually, allow the user to select their timezone

Here are the code samples used in the video:

In Application Timezone Macro

Carbon::macro('inApplicationTimezone', function() {
return $this->tz(config('app.timezone_display'));
});

In User Timezone Macro

Carbon::macro('inUserTimezone', function() {
return $this->tz(auth()->user()?->timezone ?? config('app.timezone_display'));
});

Give it a watch and learn all about Timezones and how to easily manage them!


The post Learn how to manage timezones in your Laravel Apps appeared first on Laravel News.

Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.

Read more

© 2024 Extly, CB - All rights reserved.