-1

I'm not getting the right time from my datetime field data when trying to fetch the data using fetch API. So here's the data from my database. See image: enter image description here

Now, my problem is when I'm trying to print the data using console.log it is giving me a wrong time. See image: enter image description here

Here's the field in my model:

date_created =    models.DateTimeField(auto_now=True, auto_created=True)

Here's my serializer:

class Meta:
    model = Message
    fields = [ 'date_created',]

Here's also the settings:

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Manila'

USE_I18N = True

USE_L10N = True

USE_TZ = True

I'm not sure where is the problem if it is with the timezone settings? Anyone had an experience of this?

N.Omugs
  • 321
  • 4
  • 17

1 Answers1

2

The date is same. It is formatted as a string when shown in the console because the API is returning a string.

Try doing this to format the response as a date in console.log()

console.log(new Date('2020-10-13T13:15:43.384867Z'));
Jeremy Anderson
  • 826
  • 5
  • 16