Formatting Date for Display #12011
-
I have my data stored in a Firebase Database and I'm using a q-input as a date to get the date from the user and store it. It's stored in Firebase as a string. I want to change the display so it shows as "Wednesday, January 12, 2022". So I'm using this to format the date:
I have the HH:mm:sss just so I can see the time. When I do that to change the format of the date inside my array, then display it on my page, when my date is stored as 2022-04-01 in Firebase, the date being displayed on my page is showing up as 3/31/2022. Why is it subtracting a day when it's displayed? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Did you try to use Date() object (based on |
Beta Was this translation helpful? Give feedback.
-
The output for date.formatDate('2022-04-01', 'dddd - MM/DD/YYYY - HH:mm:ss') is:
From Quasar Date Utils docs:
So, it takes us to MDN docs for Date() constructor:
So, fortunately, Quasar has import { date } from 'quasar'
const { extractDate, formatDate } = date
const startDate = extractDate(listChange.fb_eventStartDate, 'YYYY-MM-DD')
listChange.fb_eventStartDate = formatDate(startDate, 'dddd - MM/DD/YYYY - HH:mm:ss') // Your test format
listChange.fb_eventStartDate = formatDate(startDate, 'dddd, MMMM DD, YYYY') // The actual format you want |
Beta Was this translation helpful? Give feedback.
The output for
is:
Friday - 04/01/2022 - 03:00:00
on my machine. The output was different for your case, so let me explain the reason.2022-04-01
is not a date object or a UNIX timestamp, it's a timestamp string.From Quasar Date Utils docs:
So, it takes us to MDN docs for Date() constructor: