简体   繁体   中英

How to format date value before setting to a date picker input field?

Using JQuery, I created a simple date text field with dateFormat: "mmddyy" . There is no problem in the way it works. But the corresponding database field is of type DATE and stores the value in "YYYY-MM-DD" format. So, when I read the value from database and set it to the date text field, the date format appears to be "YYYY-MM-DD", but not "mmddyy". So, how can we format that database date value in JQuery before setting it to the date field ?

Thanks!

Try Jquery Date format plugin to accomplish it.

http://archive.plugins.jquery.com/project/jquery-dateFormat

如果您使用jQuery UI,请查看此页面jqueryui.com/demos/datepicker/#option-altFormat

put this code to your datebox

data-options="formatter:myformatter"

and add the function like below

 <script type="text/javascript">
    function myformatter(date){
       var y = date.getYear();
       var m = date.getMonth()+1;
       var d = date.getDate();
       return (m<10?('0'+m):m)+(d<10?('0'+d):d)+y;
    }

 </script>

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