'Changed the timezone but still getting UTC
I have changed the timezone for my laravel app to be Africa\Cairo, and i changed this in the app.php file
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
*/
'timezone' => 'Africa/Cairo',
but when i check in prodduction the time zone using Carbon::now(), i get the timezone is UTC
How can i set the timezone in Carbon
Solution 1:[1]
make sure you clear the cache, write this in your terminal (in the project directory):
php artisan config:cache
then start the project again to see the changes
Solution 2:[2]
Simply use Carbon::now('Africa/Cairo').
That should get you the correct time.
Hope this helps.
Solution 3:[3]
try this one
date_default_timezone_set('Africa/Cairo'); // set your default timezone
$date = Carbon::createFromFormat('F j, Y g:i:a', date('F j, Y g:i:a'));
dd($date->format('F j, Y g:i:a')); //November 27, 2020 7:00:pm
Solution 4:[4]
Carbon::now()->timezone('Australia/Sydney')->format('Y-m-d H:i:s');
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Omar |
| Solution 2 | dev7 |
| Solution 3 | Jowain moko |
| Solution 4 | darshan |
