pythondatetimeflask-sqlalchemydatetime-formatmarshmallow

Datetime format in flask marshmallow schema


I want to apply a custom DateTime format for the data retrieved from model using the Schema in flask marshmallow.

Currently using the schema like:

class ScheduleListSchema(ma.Schema):
    class Meta:
        fields = ('id', 'start_time', 'end_time')

In this start_time in format of 2018-12-05T03:00:00+00:00

So I want to create a custom format for the start_time value in schema.


Solution

  • You can use the code like this:

    start_time = fields.fields.DateTime(format='%Y-%m-%dT%H:%M:%S%z')