Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format date with hours, minutes and seconds when using jQuery UI Datepicker?

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.

like image 775
NETCreator Hosting - WebDesign Avatar asked Jul 03 '13 02:07

NETCreator Hosting - WebDesign


People also ask

How can change date format in jQuery ui datepicker?

inside the jQuery script code just paste the code. $( ". selector" ). datepicker({ dateFormat: 'yy-mm-dd' });

How do I change date format in datepicker?

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.

How do I change datepicker format from DD MM to YYYY?

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);


1 Answers

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);         }     }); }); 
like image 142
Arun Unnikrishnan Avatar answered Sep 30 '22 19:09

Arun Unnikrishnan