Automatically Set a Local Timezone for Users

Automatically Set a Local Timezone for Users

Laravel Timezone is a package by James Mills that sets a timezone for a user in your application and then show date/times to them in their local timezone.

It works by listening for the user login event and setting the timezone in the database. It uses Laravel GeoIP to look up the user using an IP address.

You can display the localized timezone to the user using a provided facade:

Timezone::convertToLocal($post->created_at)

You can also use the provided blade directive:

@displayDate($post->created_at)

@displayDate($post->created_at, 'Y-m-d g:i', true)

You can also convert the localized date back to UTC:

Timezone::convertFromLocal($request->get('publish_at'));

You can learn more about this package, get full installation instructions, and view the source code on GitHub at jamesmills/laravel-timezone.

Filed in: News

Newsletter

Join 31,000+ others and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Laravel Partner Seeks Team Lead / Developer
Remote
Kirschbaum Development Group, LLC
Engineering Director
Vancouver or remote (EST/PST preferred)
Engine Digital
Full-Stack Engineer
Vancouver or remote (EST/PST preferred)
Engine Digital
Sr. Software Engineer
Boca Raton - Florida, Remote - USA Only
Honorlock
Lead PHP Developer (€++)
Hoorn, The Netherlands
Portabase