Convert digital date to Chinese character date format

Source: Internet
Author: User
Tags date format return
Chinese character 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)
{

file://converts 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)
{
file://toSpecial cases are handled.
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)
{
file://InspectionEnter the date format. 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" >



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.