Getting date with timezone
- Hi I'm facing with a problem while getting date data from db.
This is how my date data stored in database.
- This is how I get the date data on blade
- This is how I get the date data with ajax request.
When I'm using blade view I'm getting the date data as is, when with ajax request it returns me the date with timezone.
What I want is I want the same format in blade like ajax request does.
How can I achieve it?
Very easily. By default, Laravel will cast created_at and updated_at to Carbon instances.
When you transform your model into an array you will also get the timezone.
$model->toArray();
Note that you can also format the date time yourself.
$model->created_at->format('D d M, Y');
Or, in your case, as an ISO string.
$model->created_at->toISOString();
Please or to participate in this conversation.