I have read many solutions online, so I also wrote a relatively simple method. Implement easyi's datebox formatting. The effect is as follows: Use "++" to separate it, and you can see whatever you like.
1. html
<span>The validity period of the certificate is until: </span> <span><input id="passvali" name="hotel.passvali"></span>
2. js
/* The validity period of the certificate is */ $('#passvali').datebox({ formatter: function(date){ var years=date.getFullYear();//Get year var months=date.getMonth()+1;//Get day var dates=date.getDate();//Get month if(months<10){//When the month is less than 10, add 0 in the first place, for example, 09 months='0'+months; } if(dates<10){//When the date is less than 10, add 0 in the first place, for example, 09 dates='0'+dates; } return years+"++"+months+"++"++"+dates;//Change according to your own needs} });Replenish:
The default format of DateBox date display is "dd/mm/yyyy". If you want to customize it into our format, you need to implement two functions, formatter and parser.
The formatter function makes the date formatted to the format we need after selecting it. The parser function tells the control how to parse our customized format after selecting the date.
Definition is as follows:
formatter: A function to format the date, the function takes a 'date' parameter and return a string value.
parser: A function to parse a date string, the function takes a 'date' string and return a date value.
Format the date to the format of yyyy-mm-dd:
$('#dd1').datebox({ formatter: function(date){ return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();}, parser: function(date){ return new Date(Date.parse(date.replace(/-/g,"/")));}});The above is the easiness method of easyi's datebox formatting that I shared with you. I hope it will be helpful to your learning.