1
votes
console.log("pre : "+vm.dailyCheckIn);
console.log(vm.temp_date.setHours(0,0,0,0));
console.log("next : "+vm.dailyCheckIn);

can someone help me with this code.

Result: before temp variable changed (original date value)

pre : Mon Oct 29 2018 16:37:24 GMT+0530 (India Standard Time)

after temp variable changed (original date value)

next : Mon Oct 29 2018 00:00:00 GMT+0530 (India Standard Time)

1

1 Answers

1
votes

It seems like that you have used the same date object in the temporary and in the actual variable. You have to create a new date object for the temporary variable. e.g

 var date = new Date();
var vm = {
  dailyCheckIn: date,
  temp_date: new Date(date) //Create a new date object
};
console.log("pre : "+vm.dailyCheckIn);
console.log(vm.temp_date.setHours(0,0,0,0));
console.log("next : "+vm.dailyCheckIn);

I hope it will help to you.