Laravel Timezone is a great package by James Mills which sets users timezone in an application and show it based on their timezone.
This package listens for the \Illuminate\Auth\Events\Login
event and will automatically set a timezone on your user model. This brillaint package uses the torann/geoip package which looks up the users location based on their IP address.
How to use?
You can show the time in users timezone using the below code
Timezone::convertToLocal($post->created_at)
Even you can use with blade directive like This
@displayDate($post->created_at) // 4th Feb 2018 1:40:am
Even with this format
@displayDate($post->created_at, 'Y-m-d g:i', true) // 2019-05-04 4:32 New York, America
You can also convert the localized date back to UTC, pretty good when relive a date for reports filters:
Timezone::convertFromLocal($request->get('publish_at'));
You may please download the package here
https://github.com/jamesmills/laravel-timezone
- Just want to thank us? Buy us a Coffee
- May be another day? Shop on Amazon using our links.
Your prices won't change but we get a small commission.
Leave a Reply