gpt4 book ai didi

JavaScript - 检查日期

转载 作者:行者123 更新时间:2023-12-03 04:49:42 25 4
gpt4 key购买 nike

如何使用第一个函数的参数(yearSlipt)给第二个函数i可以使用户输入的年份与当前年份之间存在差异。

function checkDate(date,anneSplit){
var date = new Array();
for(i = 0; i < 3 ; i++){
date[i] = prompt("entrer un date dd/mm/yyyy : ");
console.log(date[i]);
}

for(var i = 0; i < date.length ; i++)
{
daySplit = parseInt(date[i].split("/")[0]);
monthSplit = parseInt(date[i].split("/")[1]);
yearSplit = parseInt(date[i].split("/")[2]);

}
return (daySplit,monthSplit,yearSplit);
console.log(daySplit,monthSplit,yearSplit);
}

function age(ageToday,yearSplit){

checkDate();
var ageToday = new Array();
var d = new Date();
var year = d.getFullYear();
console.log(year);

ageToday = year - yearSplit;
document.write(ageToday);

}

最佳答案

对于多个返回值,您可以使用数组或 json 对象。

function checkDate(date, anneSplit) {
var date = new Array();
for (i = 0; i < 3; i++) {
date[i] = prompt("entrer un date dd/mm/yyyy : ");
console.log(date[i]);
}

for (var i = 0; i < date.length; i++) {
daySplit = parseInt(date[i].split("/")[0]);
monthSplit = parseInt(date[i].split("/")[1]);
yearSplit = parseInt(date[i].split("/")[2]);

}

return {
daySplit: daySplit,
monthSplit: monthSplit,
yearSplit: yearSplit
};
}


function age(ageToday, yearSplit) {

var checkResult = checkDate();

console.log(checkResult.yearSplit);

// var ageToday = new Array();
// var d = new Date();
// var year = d.getFullYear();

// ageToday = year - yearSplit;
//document.write(ageToday);

}

age();

关于JavaScript - 检查日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42715567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com