Search code examples
javascriptangulartypescriptunix-timestamp

convert a unix timestamp to localtime


How to multiply this with *1000 to get the unix timestamp converted to local timestamp?

I wrote this expression, but somehow the error message comes up with:

The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.

 x: [new Date(this.unixtimearray[i].time)]*1000,

In unixtimearray you get all the timestamps. I expected dd/mm/yyyy hh:mm:ss as a return value


Solution

  • Try this:

    x: new Date(this.unixtimearray[i].time*1000)
    

    If this.unixtimearray[i].time is a string:

    x: new Date(parseInt(this.unixtimearray[i].time)*1000)