How would I get a formatted date without the local timezone offset?



  • I’m trying to create a filter which would return a formatted date without being calculated with my computers local timezone offset. I have the function below and what it produces, but i’m not sure how to accomplish what i’m looking to do.

    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


  • If the date you have to give to your function is ZULU to begin with, why convert to ZULU again?

    Just stick the date you have into the formatDate function. Then you get your date as needed. 😄

    (And I am hoping I understand your problem…😊 ) If not, please expand this fiddle.

    https://jsfiddle.net/yaghf3q4/1/

    Scott



  • Using Zulu doesn’t work if i’m sitting in -7 GMT.

    See the first part of the output:


    dt = 2018-09-14T02:33:00.000Z <-- Sep 14
    formatted dt = Sep 13, 2018 <-- Sep 13



  • So, I guess I’m confused as to what the final goal is. Can you try to clarify some more please?

    Scott