我已经设置了一个函数来以我想要的格式获取当前日期和时间:
function date(){
var d = new Date();
var minutes = d.getMinutes();
var month = d.getMonth() +1;
if(minutes<10){
return (d.getDate() + "/" + month + "/" + d.getFullYear() + " " + d.getHours() + ":" + "0" + minutes);
}else{
return (d.getDate() + "/" + month + "/" + d.getFullYear() + " " + d.getHours() + ":" + minutes);}
}
我创建了一个Object
接受值的(amount,date,type)
。如何设置它,以便在对象的每个新实例中由函数date()
自动生成日期值,以便在将其推送到数组movements
时添加时间戳?
这是我的代码:
var movements =[];
//transactions
var initialBalance = new Transaction(1000,"date","cash");
var addIn = new Transaction(500,"date","cash");
var addOut = new Transaction(-300,"date","card");
//add the transactions to the movements array
movements.unshift(initialBalance);
movements.push(addIn);
movements.push(addOut);
我想用纯 JS 来做这件事。