0
votes

How can I get the starting time of a particular dateobject in milliseconds? my dateobject is in below format.

Sun Oct 16 2016 21:33:35 GMT+0530 (India Standard Time)

My input

dateobject = Sun Oct 16 2016 21:33:35 GMT+0530 (India Standard Time);

Required Output

Sun Oct 16 2016 00:00:00 GMT+0530 (India Standard Time)

Irrespective of time, I want to get the starting time of this date in milliseconds(i.e Sun Oct 16 2016 00:00:00 GMT+0530 (India Standard Time)? Sun Oct 16 2016 21:33:35 GMT+0530 (India Standard Time) -> Sun Oct 16 2016 00:00:00 GMT+0530 (India Standard Time)->1476556200000

I tried like this.

     var date_form = $filter('dateobject')(toDate, 'yyyy/MM/dd');
         (date_form=2016/10/16)
     var full_date = new Date($filter('date')(date_form, 'fullDate'));
        (full_date = Oct 16 2016 00:00:00 GMT+0530 (India Standard Time))
     var milliseconds = full_date.getMilliseconds();

I am not getting the proper output? Is this correct one?

1
var newBirthDate = $filter('date')(date_form, "yyyy-MM-dd"); - Jigar7521

1 Answers

0
votes

If I'm not wrong, you want to truncate time from date object and want milliseconds values of them.

For truncate time from date object, you don't need any angularJS code, you can do by javascript code only.

First approch

// Truncate time from exists object
toDate.setHours(0);
toDate.setMinutes(0);
toDate.setSeconds(0);
toDate.setMilliseconds(0);
console.log(toDate);

Second approach

// Create new object of date
full_date = new Date(toDate.getFullYear(), toDate.getMonth(), toDate.getDate());

getMilliseconds() method just giving part of milliseconds, its not total milliseconds. use getTime() instance of getMilliseconds() for get milliseconds.

full_date.getTime() // get milliseconds of start date