Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Laravel Carbon timezone for timestamps?

I have a project which is primarily based in CET region. I set CET in config/app.php, but all pivot timestamps in the base are stored in UTC time?

How can I set "global" timezone for timestamps?

i made this test:

<?php
$timezone = date_default_timezone_get();
echo "The current server timezone is: " . $timezone;
echo "<br />".date('m/d/Y h:i:s a', time());

$mytime = Carbon\Carbon::now();
echo "<br />".$mytime->toDateTimeString();
?>

and here's the result:

The current server timezone is: CET
06/09/2016 12:06:04 pm
2016-06-09 11:06:04

tnx Y

like image 967
Yuray Avatar asked Jun 09 '16 09:06

Yuray


People also ask

How do I set the time zone in laravel carbon?

php $timezone = date_default_timezone_get(); echo "The current server timezone is: " . $timezone; echo "<br />". date('m/d/Y h:i:s a', time()); $mytime = Carbon\Carbon::now(); echo "<br />". $mytime->toDateTimeString(); ?>

Where is the timezone configuration located in laravel?

In the laravel project open the file config/app. php , you will notice the 'timezone' => 'UTC', by default, timezone is set to UTC.


1 Answers

Update file config/app.php

Eg: 'timezone' => 'Asia/Jerusalem' instead of 'timezone' => 'UTC'

like image 145
Adam Pery Avatar answered Oct 07 '22 05:10

Adam Pery