JavaScript获取时间范围可以通过以下几种方式实现:
var currentTime = new Date();
var currentYear = currentTime.getFullYear();
var currentMonth = currentTime.getMonth();
var currentDate = currentTime.getDate();
var currentHour = currentTime.getHours();
var currentMinute = currentTime.getMinutes();
var currentSecond = currentTime.getSeconds();
var currentTime = moment();
var currentYear = currentTime.year();
var currentMonth = currentTime.month();
var currentDate = currentTime.date();
var currentHour = currentTime.hour();
var currentMinute = currentTime.minute();
var currentSecond = currentTime.second();
var firstDayOfMonth = new Date(currentYear, currentMonth, 1);
var lastDayOfMonth = new Date(currentYear, currentMonth + 1, 0);
var firstDayOfWeek = new Date(currentTime.setDate(currentDate - currentTime.getDay()));
var lastDayOfWeek = new Date(currentTime.setDate(currentDate - currentTime.getDay() + 6));
以上是获取时间范围的几种常见方法,根据具体需求选择适合的方法来获取所需的时间范围。
领取专属 10元无门槛券
手把手带您无忧上云