Change Timezone in Lumen or Laravel 5

Change timezone in laravel

After update app.php run below command and check

php artisan config:cache
php artisan cache:clear

You can create below type of route for clear cache in laravel

Route::get('/clear-cache', function() {

$configCache = Artisan::call('config:cache');
$clearCache = Artisan::call('cache:clear');
// return what you want
});

How can I set Timezone in lumen 5.2?

This is pretty easily done and shown in their documentation page:

To set configuration values at runtime, pass an array to the config
helper:

config(['app.timezone' => 'America/Chicago']);

Alternatively, in app/config.php:

'timezone' => 'UTC',

Laravel lumen is not saving right time zone

Try adding 'timezone' => env('APP_TIMEZONE', "UTC") to your config/app.php and running php artisan cache:clear after that.

Also try adding DB_TIMEZONE=+05:00 to your .env file (adjusted to your UTC offset of course)

Is there an easy way to change timezone only on view laravel?

You can use Carbon which is included in the core

$timestamp = '2014-02-06 16:34:00';
$date = Carbon::createFromFormat('Y-m-d H:i:s', $timestamp, 'Europe/Stockholm');
$date->setTimezone('UTC');

Europe/Stockholm is your default timezone and UTC is what you want to set

If you want to convert it from a model when displaying, try Accessors

public function getCreatedAtAttribute($value)
{
$date = Carbon::createFromFormat('Y-m-d H:i:s', $value, 'Europe/Stockholm');
$date->setTimezone('UTC');
return $date->toDateTimeString();
}

How to set the india time in laravel 5.2?

Go to your_project/config/app.php, there is a line:

'timezone' => ''

set it to:

'timezone' => 'Asia/Kolkata'

It will set the default timezone to Asia/Kolkata. After setting this you will get Indian time.

Here is the list of Supported Timezones

How to change timezone using date() and strtotime() in Laravel

You can set your app time zone by configuring app.php file in config folder .

To change time zone , modify the value of timezone in app.php file.

This is written in this section

|--------------------------------------------------------------------------
| 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.
|

For me i am using Asia/Kuala_Lumpur as my application time zone.

Here is the appropriate syntax :

'timezone' => 'Asia/Kuala_Lumpur'

list of timezones for PHP

NOTE : run php artisan config:clear to effect this changes



Related Topics



Leave a reply



Submit