Moment not working properly

Why I am getting Invalid date in the following case:

function formatUnixDateString(value_) {

    //https://stackoverflow.com/questions/20943089/how-to-convert-unix-timestamp-to-calendar-date-moment-js

                      if(moment(value_).isValid()){
                       //return moment.unix(value_).format('MM/DD/YYYY');

                        return moment(value_).format('L');

                       }
                       else {
                        return "";
                       }
}

Trying this line return moment(value_).format('L'); and it keeps on printing Invalid date

My dates are in this format 1522144800000

Unix timestamps need to be parsed using moment.unix(). Cf. https://momentjs.com/docs/#/parsing/

Actually, this line return moment.unix(value_).format('MM/DD/YYYY'); was also giving me Invalid Date for some reason.

works for me …

moment(1522144800000).format('MM/DD/YYYY') // "03/27/2018"

But here you aren’t using moment.unix()?

because that’s the millisecond-timestamp.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.