更改日期格式输出
Change dateformat output
我的代码中遇到了一个烦人的问题。
我想让输出日期看起来像这样:
2014/4/6
document.getElementById("nights").value = diff + " nights"; {
$('#arrival').datepicker().val();
$('#departure').datepicker().val();
var start = new Date(document.getElementById('arrival').value),
end = new Date(document.getElementById('departure').value),
currentDate = new Date(start),
between = [];
while (end > currentDate) {
between.push(new Date(currentDate));
currentDate.setDate(currentDate.getDate() + 1);
}
$('#lista').html(between.join('<br> '));
};
在哪里可以更改输出格式?
在while
循环中,尝试:
while (end > currentDate) {
var month = currentDate.getMonth() + 1;
var day = currentDate.getDate();
var year = currentDate.getUTCFullYear();
between.push(month + '-' + day + '-' + year);
currentDate.setDate(currentDate.getDate() + 1);
}
看起来您正在做更多的事情:new Date(variable)
不必要的。
相关文章:
- Datetime格式为Friendly Time.Moment JS输出错误
- 有没有一种方法可以从两个标签之间提取文本,并以我选择的格式输出
- 输出文本不't以正确格式显示
- 没有获得 json .save 的输出,格式为 pars.html
- 如果 CreateJS 库支持 Texture Packer 的 JSON 输出格式
- 获取表格格式的 Javascript 输出
- 如何使用 JQuQuery 解析 JSON 对象并在 HTML 页面中以表格格式打印输出
- 如何以绘图表格式输出PHP结果
- 查看不同输出格式时的内容协商
- HTML表单Mailto输出格式
- Nashorn探查器输出格式
- 将REST JSON输出格式化为另一种格式
- 如何更改serializeObject输出格式?
- moment(). toobject()输出格式
- POST表单到新选项卡.输出格式为PDF
- ASP.jQuery UI自动完成的输出格式(显示值标签键对)
- Angular-ui: Date -不同的输出格式
- 输出格式不正确
- 对输出格式使用相同的解析格式
- 节点.js大数字的输出格式