Laravel Tutorials

Learn how to manage timezones in your Laravel Apps

Published

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!

Eric L. Barnes photo

Eric is the creator of Laravel News and has been covering Laravel since 2012.

Sponsored

acquaintsoft logo
Acquaint Softtech

Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Visit Acquaint Softtech

The latest

View all →
The Laracon Archive image

The Laracon Archive

Read article
Group Adjacent Collection Items in Laravel with chunkBy() image

Group Adjacent Collection Items in Laravel with chunkBy()

Read article
Laravel queue:work Now Prints Why the Worker Stopped image

Laravel queue:work Now Prints Why the Worker Stopped

Read article
Sidecar Brings Statamic's Control Panel to Your Existing Markdown Sites image

Sidecar Brings Statamic's Control Panel to Your Existing Markdown Sites

Read article
Collections chunkBy() and Storage Path Hardening in Laravel 13.30 image

Collections chunkBy() and Storage Path Hardening in Laravel 13.30

Read article
Forte: Parse and Rewrite Laravel Blade Templates image

Forte: Parse and Rewrite Laravel Blade Templates

Read article