简体   繁体   中英

Convert date time to milliseconds in AngularJS

I have currentDate:

var clockFormat = 'dd MMM, yyyy hh:mm:ss a';
var currentDate = dateFilter(new Date(), clockFormat);

Is it possible to convert currentDate to milliseconds in AngularJS?
Or, how to call javascript function getTime which returns milliseconds?

var currentDate = dateFilter(new Date(), clockFormat).getTime();

Return error!

Thanks in advance,
Srdjan

Srdjan, I answered this exact question a few minutes ago for a different user who deleted the question. The reason why:

var currentDate = dateFilter(new Date(), clockFormat).getTime;

Does not work is because you are using the .getTime() function which is native to Date types on the dateFilter instead of the new Date() like so:

var date = new Date();
var currentDate = dateFilter(date.getMilliseconds(), clockFormat);

or as you mentioned in comments you want to use .getTime():

var date = new Date();
var currentDate = dateFilter(date.getTime(), clockFormat);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM