
正文
js判断当前月的最后一天,js判断日期是否是月末
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
js如何获取上个月第一天和最后一天
最后一天 var date = new Date(); var endDate = new Date(date.getFullYear(), date.getMonth(), 0).getDate();
相关问答
Q1: js如何获取季末值,如现在的时间是3月,那么季末值就是3月最后一天,若是4月,那么季末值就是6月最后一天
script type="text/javascript"
function fun (){
var today=new Date();
var m=today.getMonth()+1;
alert(m);
if(m=="1"||m=="2"||m=="3"){
alert("3月31日");
}
if(m=="4"||m=="5"||m=="6"){
alert("6月30日");
}
if(m=="7"||m=="8"||m=="9"){
alert("9月31日");
}
if(m=="10"||m=="11"||m=="12"){
alert("12月31日");
}
}
/script
input type="button" value="aaaaa" onclick="fun();"
Q2: js 获取当前月和当前周的第一天和最后一天
前言:需求里面有,做了就记录一下
第一种:获取当前月 当前周 的第一天 时分秒都为0,最后一天时分秒为23:59:59
ps:如果想获得指定日期的当前周,new Date('2020-1-2') 传参就可以了
//获取当前周
getTime(){
var date = new Date();
// 本周一的日期
date.setDate(date.getDate() - date.getDay() + 1);
var begin = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " 00:00:00";
// 本周日的日期
date.setDate(date.getDate() + 6);
var end = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " 23:59:59";
let timeInfo={
begin:begin,
end:end
}
return timeInfo
}
//获取当前月
getMtime(){
var data=new Date();
data.setDate(1);
data.setHours(0);
data.setSeconds(0);
data.setMinutes(0);
var start = data.getTime();
var currentMonth = data.getMonth();
var nextMonth = ++currentMonth;
var nextMonthFirstDay = new Date(
data.getFullYear(),
nextMonth,
1
);
var end = nextMonthFirstDay-1;
let timeInfo={
begin: this.timestampToTime(start),//这里调用时间戳转年月日时分秒方法
end: this.timestampToTime(end)
}
return timeInfo
}
//时间戳转年月日时分秒方法
timestampToTime (cjsj) {
var date = new Date(cjsj) //时间戳为10位需*1000,时间戳为13位的话不需乘1000
var Y = date.getFullYear() + '-'
var M = (date.getMonth()+1 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'
var D = (date.getDate() 10 ? '0'+date.getDate() : date.getDate()) + ' ';
var h = (date.getHours() 10 ? '0'+date.getHours() : date.getHours()) + ':';
var m = (date.getMinutes() 10 ? '0'+date.getMinutes() : date.getMinutes())+ ':';
var s = (date.getSeconds() 10 ? '0'+date.getSeconds() : date.getSeconds());
return Y+M+D+h+m+s;
}
Q3: .net或js判断所给时间是不是月末
是不是月末很简单,不需要搞的那么复杂,把给出的时间加上一天,然后再获取这个新时间的月份,如果等于之前那个时间的月份,就不是月末,以当前时间为例
string str=DateTime.Now.AddDays(1).Month == DateTime.Now.Month ? "不是月末" : "是月末";
JS应该有相同的做法吧
Q4: js代码实现,如何获取当前月份的最后一天
代码如上,原理是,设定指定月份的下个月第一天,减去1毫秒,就是上个月最后一天。
测试输出结果,以下结果分别是29、28:
js如何获得今年最后一天的日期:
script type="text/javascript"
function getYearLastDay(){
return new Date().getFullYear()+"年12月31号";
}
alert(getYearLastDay());
/script
关于js判断当前月的最后一天和js判断日期是否是月末的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






