如何格式化我的日期从 1.1.2011 到 01.01.2011
我有一个小脚本,用于两个日期选择器来计算夜晚,并且用户无法选择比今天更早的日期,不,我无法显示正确格式的日期,
如果我访问该页面,它只显示我需要的到达日期,选择出发日期后,它会显示正确格式的出发日期,我该如何解决这个问题?
var my2Date = new Date();
var pretty2Date = my2Date.getDate() + '.' + (my2Date.getMonth() + 1) + '.' + my2Date.getFullYear();
$("#abreise").val(pretty2Date);
$("#anreise, #abreise").datepicker({
onSelect: DatePicked,
minDate: new Date()
});
$("#nacht").change(DatePicked);
DatePicked();
});
I have a small script for two datepickers to calculate the nights and that the user cant select an earlier date then today, no i have trouble to display the right formatted date,
if i visit the page it shows me only the arrivaldate like i need, after selecting the departuredate it shows me the right formatted departuredate, how could i fix this?
var my2Date = new Date();
var pretty2Date = my2Date.getDate() + '.' + (my2Date.getMonth() + 1) + '.' + my2Date.getFullYear();
$("#abreise").val(pretty2Date);
$("#anreise, #abreise").datepicker({
onSelect: DatePicked,
minDate: new Date()
});
$("#nacht").change(DatePicked);
DatePicked();
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您所需要做的就是将日期格式设置为:
dd.mm.yy
All you need to do is set the date format to:
dd.mm.yy
您还可以使用 http://www.datejs.com/ 日期库将日期和时间格式化为任何形状和形式。
You can also use http://www.datejs.com/ date library to format date and time in any shape and form.
您需要改变使约会“漂亮”的方式:
应该变成:
但是,我会建议您使用此类插件的插件:http://stevenlevithan.com/assets/misc/date.format.js
如果您使用它,那么您可以像这样格式化所有日期实例:
这更易于维护。
You need to change the way you make your dates "pretty":
Should become:
However, I would advance you to use a plugin for this kind of stuff: http://stevenlevithan.com/assets/misc/date.format.js
If you use this, then you can just format all your Date-instances like this:
This is much more maintainable.