6

I built my backend API with the Django rest framework in which the model has a DateTimeField.

date = models.DateTimeField(auto_now_add=True)

When I get the data from the API to React I get something like this

2019-01-20T19:24:58.674435Z

How can I parse this in javascript and convert it to a readable form?

3

1 Answer 1

3

It's possible to do it through your serializer. Given that you name it ''date'' in your model, you can do the following.

class ObjectSerializer(serializers.ModelSerializer):
    date = serializers.DateTimeField(format="%d-%m-%Y %H:%M:%S")

    class Meta:
        model = Object
        fields='__all__'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.