This question already has an answer here:
The default timezone that is set in config/app
file is UTC
but for a short part of my project I want to change it to Asia/Tehran
. I use config() function to set timezone value to what I want but it doesn't affecton date result.
please look to the below example:
echo date('Y-m-d H:i:s',time()) . '<br>'; //here the current timezone is UTC
config(['app.timezone' => 'Asia/Tehran']); // I've set new timezone
echo date('Y-m-d H:i:s',time()); //here the current timezone is Asia/Tehran
The above code result is same but they should be different. Where is the problem?
</div>
custom timezone config doesn't affect outputted date, try this:
date_default_timezone_set('Asia/Tehran');
echo date('Y-m-d H:i:s',time());
I think that config changed at runtime will not take effect by the way why not to use Carbon
$timestamp = '2018-02-08 18:39:00';
$date = Carbon::createFromFormat('Y-m-d H:i:s', $timestamp, 'Europe/Stockholm');
$date->setTimezone('UTC');