Reputation: 79
I want to format the Laravel date format generated by timestamps, but I want to do that in the front end with Javascript, the time value is something like this 2022-01-03T19:16:16.000000Z
, so what I want to do is to format it to something like this: 02 Jan 2021
Upvotes: 0
Views: 462
Reputation: 1916
Here's a previous post on how you can accomplish this: How to handle datetime between php (Laravel api) and javascript (AngularJS)
However, it's worth noting that Laravel handles this for you. See documentation on Date Casting.
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'created_at' => 'datetime:Y-m-d',
];
As the post suggests you can use momentjs:
correctTime = moment('<YOUR_UTC_TIME_STRING>').format();
Upvotes: 2
Reputation: 378
You don't need to format it in your frontend, you can use carbon to accomplish that task in your laravel backend, it is simple and straight forward
Upvotes: 0