How to format the datebox of easyui and the easyuidatebox

Source: Internet
Author: User

How to format the datebox of easyui and the easyuidatebox

After reading a lot of solutions on the internet, I also wrote a simple method. Format the datebox of easyui. The effect is as follows, separated by "+ +" to see what you like.

 

1. html

<Span class = "span1"> valid certificate: </span> <input id = "passvali" name = "hotel. passvali"> </span>

2. js

/* The validity period of the credential is */$ ('# passvali '). datebox ({formatter: function (date) {var years = date. getFullYear (); // get the annual var months = date. getMonth () + 1; // obtain the daily var dates = date. getDate (); // obtain the month if (months <10) {// Add 0 before the month is less than 10, for example, 09 months = '0' + months ;} if (dates <10) {// Add 0 before the date is less than 10, for example, 09 dates = '0' + dates ;} return years + "++" + months + "++" + dates; // make changes as needed }});

Supplement:

The default format of DateBox date display is "dd/mm/yyyy". to customize the format, you need to implement two functions, formatter and parser.
The formatter function allows you to format a date as needed. After you select a date, the parser function tells the control how to parse the custom format.
Definition:
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.
For example, format the date to 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 simplest method for formatting datebox of easyui, which is shared with you. I hope it will be helpful for your learning.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.