>PROBLEM
Supposing using date-and-time lib:
npm install date-and-time --save
const date = require('date-and-time')
and the date returning the standard format, something like this (locale: Brazil):
obj.createdAt = 'Fri Aug 26 2022 21:14:34 GMT-0300 (Horário Padrão de Brasília)';
the compiler throws the following error:
date-and-time offset = dateObj.getTimezoneOffset()
TypeError: Cannot read properties of undefined (reading 'getTimezoneOffset')
>SOLUTION
***WRONG
created_at: date.format(obj.createdAt, 'YYYY/MM/DD HH:mm:ss'),
>RIGHT
created_at: date.format(new Date(obj.createdAt), 'YYYY/MM/DD HH:mm:ss'),
>ENV
Node: 16.13.1
Package Manager: npm 8.5.4
OS: win32 x64
No comments:
Post a Comment