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:
@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.
@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 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.
@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.
@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:
@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');
@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.