Lijo Vijayan
Lijo Vijayan

Reputation: 85

Typescript: Convert '28/11/2019 00:00:00.000' format to timestamp

How to convert date with milliseconds in typescript(Angular)

for example convert 28/11/2019 00:00:00.000 to a timestamp

Upvotes: 0

Views: 707

Answers (2)

Sachin Gupta
Sachin Gupta

Reputation: 5301

You need to convert the string "28/11/2019 00:00:00.000" into a date first, then you can get the milliseconds. To convert the data from string to a Date object, you can use moment package from npm.

Then use as :

 var momObject = moment("28/11/2019 00:00:00.000",'dd/MM/yyyy hh:mm:ss.sss')

will give you a Moment object. Then use js Date class to get time in ms:

new Date(momObj.toISOString()).getTime();

Upvotes: 1

Wandrille
Wandrille

Reputation: 6801

You need to convert 28/11/2019 00:00:00.000 into :

2019-11-28T00:00:00 and then you can use new Date(myDate).getTime() / 1000

Upvotes: 0

Related Questions