Is it possible to format a date with jQuery UI Datepicker as to show hours, minutes and seconds?
This is my current mockup:
$(function() { $('#datepicker').datepicker({ dateFormat: 'yyy-dd-mm HH:MM:ss' }).val(); });
<html> <head> <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css"> <title>snippet</title> </head> <body> <input type="text" id="datepicker"> <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <script src="https://code.jquery.com/ui/1.9.2/jquery-ui.min.js"></script>
When I call .datepicker({ dateFormat: 'yyy-dd-mm HH:MM:ss' })
the returned value is:
201313-07-03 HH:July:ss
Here is a JSFiddle.
inside the jQuery script code just paste the code. $( ". selector" ). datepicker({ dateFormat: 'yy-mm-dd' });
By default, the date format of the jQuery UI Datepicker is the US format mm/dd/yy, but we can set it to a custom display format, eg: for European dates dd-mm-yyyy and so on. The solution is to use the date picker dateFormat option.
var year = 2014; var month = 5; var day = 10; var realDate = new Date(year, month - 1, day); // months are 0-based! $('#MainContent_txtDataConsegna'). datepicker({ dateFormat: 'dd/mm/yyyy' }); // format to show $('#MainContent_txtDataConsegna'). datepicker('setDate', realDate);
Try this fiddle
$(function() { $('#datepicker').datepicker({ dateFormat: 'yy-dd-mm', onSelect: function(datetext) { var d = new Date(); // for now var h = d.getHours(); h = (h < 10) ? ("0" + h) : h ; var m = d.getMinutes(); m = (m < 10) ? ("0" + m) : m ; var s = d.getSeconds(); s = (s < 10) ? ("0" + s) : s ; datetext = datetext + " " + h + ":" + m + ":" + s; $('#datepicker').val(datetext); } }); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With