javascript 如何在javascript中获取datepicker值的完整(包括小时、分钟和秒)日期格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33773317/
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 complete(include hour,minute and seconds) date format of datepicker value in javascript
提问by Bibin James
I am using the UI DatePicker from jQuery UI as the stand alone picker.. i have this code
我使用来自 jQuery UI 的 UI DatePicker 作为独立的选择器..我有这个代码
<div id="datepicker"></div>
And the follow JS
然后跟随JS
$('#datepicker').datepicker();
When i try to return the value with this code:
当我尝试使用此代码返回值时:
var date = $('#datepicker').datepicker('getDate');
I am returned this...
我被退回这个...
Sun Nov 01 2015 00:00:00 GMT+0530 (India Standard Time)
Which is totally the wrong format... Is there a way i can get the format like
这是完全错误的格式......有没有办法我可以得到这样的格式
Sun Nov 01 2015 05:30:00 GMT+0530 (India Standard Time)
??
??
采纳答案by Anoop B.K
You can use DateTimePicker to specify the dateFormat and timeFormat something like this :
您可以使用 DateTimePicker 指定 dateFormat 和 timeFormat ,如下所示:
$('#datepicker').datetimepicker({
dateFormat: "yy-mm-dd",
timeFormat: "hh:mm:ss"
});
Or else you can try adding get methodlike :
或者,您可以尝试添加get 方法,例如:
$(function() {
$('#datepicker').datepicker({
dateFormat: 'D M dd yy',
onSelect: function(datetext){
var d = new Date(); // for now
datetext=datetext+" "+d.getHours()+": "+d.getMinutes()+": "+d.getSeconds();
$('#datepicker').val(datetext);
},
});
});
Check fiddle : http://jsfiddle.net/5qkt8e06/62/
检查小提琴:http: //jsfiddle.net/5qkt8e06/62/