简体   繁体   中英

How to get complete(include hour,minute and seconds) date format of datepicker value in javascript

I am using the UI DatePicker from jQuery UI as the stand alone picker.. i have this code

<div id="datepicker"></div>

And the follow 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)

??

You can use DateTimePicker to specify the dateFormat and timeFormat something like this :

$('#datepicker').datetimepicker({
    dateFormat: "yy-mm-dd",
    timeFormat:  "hh:mm:ss"
});

Or else you can try adding get method like :

$(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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM