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">