0

I'm using the Quasar framework and i'm trying to figure out how to display a date in a formatted GMT date rather than one calculated using the local timezone my computer is in.

I'm specifically using the Quasar Date Utils

import { date } from 'quasar'

export function ciiFormatDate (dt, format = 'MMM DD, YYYY') {
  console.log('---------------')
  console.log('dt = ', dt)
  console.log('formatted dt = ', date.formatDate(dt, format))
  console.log('---------------')
  console.log('newdt = ', new Date(dt))
  console.log('formatted newdt = ', date.formatDate(new Date(dt), format))
  console.log('---------------')
  console.log('new date = ', new Date(dt).toUTCString())
  console.log('formatted new date = ', date.formatDate(new Date(dt).toUTCString(), format))
}

produces:

---------------
dt =  2018-09-14T02:33:00.000Z
formatted dt =  Sep 13, 2018
---------------
newdt =  Thu Sep 13 2018 19:33:00 GMT-0700 (Pacific Daylight Time)
formatted newdt =  Sep 13, 2018
---------------
new date =  Fri, 14 Sep 2018 02:33:00 GMT
formatted new date =  Sep 13, 2018 <-- TRYING TO GE THIS TO SHOW Sep 14th
Catfish
  • 17,019
  • 47
  • 183
  • 323
  • 1
    So why not use *toUTCString* and just trim the time part? – RobG Sep 17 '18 at 01:52
  • I'd have to trim the day part too. It's a possible solution, but doesn't seem like a great one. Maybe it is though – Catfish Sep 17 '18 at 02:06
  • It's that or [*How to format a JavaScript date*](https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date). – RobG Sep 17 '18 at 09:04
  • @RobG Are you saying you have experience with the quasar date util and you're telling me there is no way to do it using this util? – Catfish Sep 17 '18 at 16:00
  • @RobG Thinking about this deeper I can't just `toUTCString` and strip off the day and the time b/c this method has `format` as the second parameter. If someone passes in a different format, my code won't be displaying the correct date anymore – Catfish Sep 17 '18 at 16:57
  • I don't have experience with quasar. There's some documentation for the quasar date utility [*here*](https://quasar-framework.org/components/date-utils.html). There is a statement "*You can pass a third argument (a Boolean) for setting UTC time (true) instead of local time.*". You can also try adjusting the time for the local timezone offset so that the local time has the same values as UTC. – RobG Sep 17 '18 at 20:26

0 Answers0