Javascript| Chinese Characters | date <script>
/*
Function: YYYY-MM-DD digital date into Chinese characters
Example: 1984-3-7-> March 7, 1984
Call: Baodate2chinese ("1984-3-7")
*/
var Chinese = [' 0 ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ', ' seven ', ' eight ', ' nine '];
var len = [' Ten '];
var ydm =[' year ', ' Month ', ' Day '];
function Num2chinese (s)
{
//Translate a single number into Chinese.
S= "" +s;
Slen = s.length;
var result= "";
for (Var i=0;i<slen;i++)
{
Result+=chinese[s.charat (i)];
}
return result;
}
function n2c (s)
{
//handling of special cases.
S= "" +s;
var result= "";
if (s.length==2)
{
if (S.charat (0) = = "1")
{
if (S.charat (1) = = "0") return len[0];
return Len[0]+chinese[s.charat (1)];
}
if (S.charat (1) = = "0") return Chinese[s.charat (0)]+len[0];
Return Chinese[s.charat (0)]+len[0]+chinese[s.charat (1)];
}
return Num2chinese (s)
}
function Baodate2chinese (s)
{
//Verify the date format entered. and extract the relevant numbers.
var Datepat =/^ (\d{2}|\d{4}) (\/|-) (\d{1,2}) (\2) (\d{1,2}) $/;
var Matcharray = S.match (Datepat);
var ok= "";
if (Matcharray = null) return false;
for (Var i=1;i<matcharray.length;i=i+2)
{
OK+=N2C (matcharray[i]-0) +ydm[(i-1)/2];
}
return OK;
}
</script>
Yyyy-mm-dd:<input type=text name= "mydate" value= "1984-3-7" >
Chinese display: <input type=text name= "Okdate" >
<input Type=button
Value= "Convert" >
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.