jQuery 如何使用jquery获取当前日期?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4710166/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get current date using jquery?
提问by Rinkal Bhanderi
I am using a calender plug-in and I want to populate the current date into a text field. How can I do this using jquery?
我正在使用日历插件并且我想将当前日期填充到文本字段中。我如何使用 jquery 做到这一点?
回答by Naveed
You can get current date in JavaScript:
您可以在 JavaScript 中获取当前日期:
var now = new Date();
If you are using jQuery DatePickeryou can apply it on any textfield like this:
如果您使用 jQuery DatePicker,您可以将它应用到任何文本字段,如下所示:
$('input.youTextFieldClass').datepicker({ dateFormat: 'mm/dd/yy',
changeMonth: true,
changeYear: true,
yearRange: '-70:+10',
constrainInput: false,
duration: '',
gotoCurrent: true});
If you want to set current date in textfields as page load:
$("input.youTextFieldClass").datepicker('setDate', new Date());