Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Another_X's avatar

Best way to output date?

What is the best way to output date in Laravel? When I use PHP date function returned date is not correct. I set the timezone in configuration to be "America/New_York".

I also tried to output PHP time and this is what I get:

date_default_timezone_set: America/New_York date.timezone: America/Los_Angeles

If i remember correctly date function uses date.timezone configuration. So how to make sure we are using laravel configuration for date output?

0 likes
13 replies
jaythanki's avatar

@ANOTHER_X Can you specified more..? output date for display purpose or for storing in database for further usage. ?

Another_X's avatar

@jaythanki output for display purpose in this case. But should be done in both case in the end, so data coming from forms is correctly set in the database.

kvithalani's avatar

@Another_X If you are changing time zone then it will take that time zone's date while you create or update anything. So you can check dates in your database. i.e. "created_date" and "updated_date".

Another_X's avatar

@kinjs12 not sure what you mean here. How do i know which timezone is used based on a date in "created at" the field?

kvithalani's avatar

@Another_X If you have added timestamp (created_at and updated_at) in your table then by default it will take "utc" time zone from config/app.php file. But if you change time zone then it will take that time zone(which you have given in config/app.php file). So you can check that dates with time.

Another_X's avatar

@kinjs12 I checked and date in the database is set to America/New_York, but output in template is day in advance, so it seems like output is set to America/Los_Angeles.

kvithalani's avatar

@Another_X , are you in America/Los_Angele time zone?? Because by default browser will take current time zone date. So here you need to set time zone at front end. So you can use this way:

 $user->created_at->timezone('America/New_York')->format('H:i');
jaythanki's avatar

@Another_X as per your case you want to display date as per timezone right.?

you can by using carbon :

use Carbon;

//convert as per timezone
$timestamp = '2018-10-03 16:34:00'; // Your Date
$date = Carbon::createFromFormat('Y-m-d H:i:s', $timestamp, 'America/New_York');
Another_X's avatar

@kinjs12 @jaythanki problem was in javascript part of the code. The date was outputted correctly by Laravel but problem was that vuejs component calculated offset by time zone, so that was -04:00h difference.

2 likes
jaythanki's avatar

hey @Another_X - you had solved that issue right than you can mark as solution so it may help others too. thank you.

Please or to participate in this conversation.