programming-examples/js/Date/Write a JavaScript function to get the week start date..js

11 lines
253 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
function startOfWeek(date)
{
var diff = date.getDate() - date.getDay() + (date.getDay() === 0 ? -6 : 1);
return new Date(date.setDate(diff));
}
dt = new Date();
console.log(startOfWeek(dt).toString());