js文件,获取时间16年8月,显示确是116年8月,求解
答案:2 悬赏:60 手机版
解决时间 2021-04-29 03:06
- 提问者网友:一抹荒凉废墟
- 2021-04-28 07:34
js文件,获取时间16年8月,显示确是116年8月,求解
最佳答案
- 五星知识达人网友:怙棘
- 2021-04-28 08:40
//我想是获取时间时候出了问题。js获取时间:
var date = new Date();
var now = "";
var nowYear, nowMonth, nowDate, nowHours, nowMinutes, nowSeconds
nowYear = date.getFullYear();
nowMonth = date.getMonth() + 1; //取月的时候取的是当前月-1,如果想取当前月+1就可以了
nowDate = date.getDate();
nowHours = date.getHours();
nowMinutes = date.getMinutes();
nowSeconds = date.getSeconds();
if (nowMonth < 10) {
nowMonth = "0" + nowMonth;
}
if (nowDate < 10) {
nowDate = "0" + nowDate;
}
if (nowHours < 10) {
nowHours = "0" + nowHours;
}
if (nowMinutes < 10) {
nowMinutes = "0" + nowMinutes;
}
if (nowSeconds < 10) {
nowSeconds = "0" + nowSeconds;
}
now = nowYear + "年" + nowMonth + "月" + nowDate + "日 " + ' ' + nowHours + ":" + nowMinutes + ":" + nowSeconds;
var date = new Date();
var now = "";
var nowYear, nowMonth, nowDate, nowHours, nowMinutes, nowSeconds
nowYear = date.getFullYear();
nowMonth = date.getMonth() + 1; //取月的时候取的是当前月-1,如果想取当前月+1就可以了
nowDate = date.getDate();
nowHours = date.getHours();
nowMinutes = date.getMinutes();
nowSeconds = date.getSeconds();
if (nowMonth < 10) {
nowMonth = "0" + nowMonth;
}
if (nowDate < 10) {
nowDate = "0" + nowDate;
}
if (nowHours < 10) {
nowHours = "0" + nowHours;
}
if (nowMinutes < 10) {
nowMinutes = "0" + nowMinutes;
}
if (nowSeconds < 10) {
nowSeconds = "0" + nowSeconds;
}
now = nowYear + "年" + nowMonth + "月" + nowDate + "日 " + ' ' + nowHours + ":" + nowMinutes + ":" + nowSeconds;
全部回答
- 1楼网友:旧脸谱
- 2021-04-28 09:13
获取nowyear的代码贴出来
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯