-5
var date = new Date();
let format = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
console.log(format); // result : 2021-10-28

Now I want to set it's hours and minutes as 00:00 and 23:59. Example: 2021-10-28 00:00 and 2021-10-28 23:59 ,Thanks

deskeay
  • 263
  • 2
  • 15

1 Answers1

1

If I understand correctly, you want to get the first and last minute of today? You can use:

var date = new Date();
console.log(date); // result: 2021-10-28 15:31

date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
console.log(date); // result: 2021-10-28 00:00

date.setHours(23);
date.setMinutes(59);
date.setSeconds(59);
console.log(date); // result: 2021-10-28 23:59
Dan P
  • 786
  • 7
  • 18