I'm having a bit of problem with a date conversion in JavaScript. I have string in format "2023-12-14" that I would like to convert to its corresponding Day of week in a Vue template( In this instance Thursday). I am using this formula :
{{ new Date("2023-12-14").toLocaleString('en-us', {
timeZone: 'America/New_York',
weekday: 'long'
}) }}
Unfortunately this is printing out Wednesday instead of Thursday. I figure it has something to do with the UTC but I have included timezone parameter in .toLocaleString but still printing wrong date. It is the same with several other dates I need to convert, they all print out a day earlier then expected. Any help would be much appreciated...
Update Info: My template is
{{new Date(gameScores[n -
1].parameters.date).toLocaleString('en-us', {
timeZone: 'America/New_York',
weekday: 'long'
}) }}
Can I output the correct day of week from the template expression?
You can write a functional abstraction to parse the date numerically before using the
Date()constructor. Modify if needed to suit your needs: