<Script>
/*
Function: Convert YYYY-MM-DD numeric date to Chinese Character
Example: March 7, 1984->
Call: baodate2chinese ("1984-3-7 ")
*/
Var chinese = [zero, one, two, three, four, five, six, seven, eight, nine];
Var len = [10];
Var ydm = [year, month, day];
Function num2chinese (s)
{
// Convert a single number to 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)
{
// Handle 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 input date format and extract related 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 onclick = "document. all. okdate. value = baodate2chinese (document. all. mydate. value )"
Value = "Conversion">