Javed
Javed

Reputation: 857

Laravel : Set Timestamp return only custom date

In my app I just set timezone as UTC when I return response I got date format as UTC.

    "created_at": {
        "date": "2018-05-18 15:17:37.000000",
        "timezone_type": 3,
        "timezone": "UTC"
    },
    "updated_at": {
        "date": "2018-06-08 05:49:05.000000",
        "timezone_type": 3,
        "timezone": "UTC"
    }

But I only need updated_at : 2018-06-08 05:49:05, I do not need timzone type, timezone.. Expected :

    "country"   : "United States Of America",
    "region"    : "Northeast",
    "updated_at": "2018-06-08 05:49:05"

How can i do this ?

Upvotes: 1

Views: 1346

Answers (1)

Tartar
Tartar

Reputation: 5452

Take a look at this

https://laravel.com/docs/5.6/eloquent-mutators#date-mutators

You can do this by using an accessor method in your model and the time format you want.

To format date and time easily, use Carbon

https://carbon.nesbot.com/

Upvotes: 2

Related Questions