JavaScript - Custom timestamp parsing with Datejs

63 views Asked by At

i've got a custom timestamp which looks like this: "Jan 15 2020 11:11:50.000 +0000". I need to transfer the timestamp mentioned above in an Epoch-Timestamp. I've tried it serval times - Right now my code looks like this:

oldTimeStamp = 'Jan 15 2020 11:11:50.000 +0000';
newTimeStamp = Date.parse(oldTimeStamp).toString('MMM dd yyyy hh:mm:ss.SSS Z')
console.log(newTimeStamp)

I have to use Datejs to transfrom the date.

Anyone got an idea how to fix it?

Thanks

1

There are 1 answers

4
mgreif On

As far as i understood, this could help you transorming oldTimeStamp into a timestamp or UTC-string

    oldTimeStamp = 'Jan 15 2020 11:11:50.000 +0000';
    newTimeStamp = new Date(oldTimeStamp).getTime()
    utcString = new Date(oldTimeStamp).toUTCString()

    console.log("Timestamp: ", newTimeStamp) // -> Timestamp:  1579086710000
    console.log("UTC: ", utcString) // -> UTC:  Wed, 15 Jan 2020 11:11:50 GMT

Using DateJS you can format the timestamp into any format