有没有办法将此函数转换为moment.js?它像70%js和30%moment.js
功能
function muestraDias() {
var day=0;
var server = TimeSync.serverTime() //
var d= new Date();
var weekdays = new Array(7);
weekdays[0] = "Domingo";
weekdays[1] = "Lunes";
weekdays[2] = "Martes";
weekdays[3] = "Miercoles";
weekdays[4] = "Jueves";
weekdays[5] = "Viernes";
weekdays[6] = "Sabado";
for (i=1; i<8;i++){
document.getElementById("sub"+i).innerHTML = moment(d).locale("es").format('L');
day=weekdays[d.getDay()]; // this too
document.getElementById("titulo"+i).innerHTML =day;
document.getElementById("fecha"+i).innerHTML = moment(d).locale("es").format('LLL');
d.setDate(d.getDate() +1); // Need to change this to functionality moment
}
}
Alredy尝试删除d变量,但 for 停止工作,它可能会将此函数更改为完整的moment.js但具有相同的功能?
答案 0 :(得分:0)
首先将所有内容放在Rendered Function
Meteor.call('tomaFecha',function(error,fecha){
if(error){
console.log("no se pudo mostrar la fecha");
} else {
dia = moment(fecha).locale("es");
var d = dia;
for (i=1; i<8;i++){
document.getElementById("sub"+i).innerHTML = d.format('L');
document.getElementById("titulo"+i).innerHTML = d.format('dddd');
// document.getElementById("dia"+i).innerHTML = d.format('dddd');
//document.getElementById("fecha"+i).innerHTML = d.format('LLL');
d.add(1,'days');
}
}
});
我们还使用Meteor.call
来获取服务器时间,并忽略浏览器时间
<强> Server.js 强>
Meteor.methods({
tomaFecha : function(){
var d = (new Date())
return d;
}
})
它有效