Date. format: date. format

Source: Internet
Author: User

Date. format: date. format

$1... $9 attribute in RegExp:

Returns the last nine parts stored during the pattern match.

$1... the attribute value of $9 is modified. You can specify any number of child matches with parentheses in a regular expression, but you can store up to 9.

Example:

<script type="text/javascript">var pattern = /(\w+)@(\w+)\.(\w+)/g,str = "Please send mail to george@contoso.com and someone@example.com. Thanks!",result = pattern.test(str);alert(RegExp.$1+"-"+RegExp.$2+"-"+RegExp.$3);</script>
Print: george-contoso-com.

RegExp. $1 matches the first child match with parentheses, print: george, and so on. RegExp. $2 matches the second child match with parentheses, so print: contoso.
Then analyze the date format conversion:

If the date format to be converted is specified as "yyy-MM-dd ".

If we want to obtain the year in this format, consider RegExp. $1 feature. We can match this format by/(y +)/to obtain the number of digits of the Year, and then extract the year information of the current date and replace it.

For example:

<Script type = "text/javascript"> var pattern = "yyy", result =/(y + )/. test (pattern), year = String (new Date (). getFullYear (); pattern = pattern. replace (RegExp. $1, year. substr (4-RegExp. $1. length); alert (pattern); </script>
Therefore, we can write the date conversion Code as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 


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.