转换“NUMBER中的月份” in to“Month in WORD”:22-09-2012 - > 22-SEP-2012 [英] Convert "Month in NUMBER" in to "Month in WORD": 22-09-2012--> 22-SEP-2012
本文介绍了转换“NUMBER中的月份” in to“Month in WORD”:22-09-2012 - > 22-SEP-2012的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我需要将月份转换为单词读取月份。
我做了一个javascript函数转换如下所示:
function convert(mycontrolclientID)
{
var ldtDate = mycontrol。 value ;
var month = new Array();
var lstrDay,lstrMonth,lstrYear,lstrMonthinword = 1 ,lstrDate;
month = [ ,' JAN',' FEB',' MAR',' < span class =code-string> APR',' MAY',' JUN',' JUL',' AUG',' SEP',' OCT',' NOV', ' DEC'];
lstrDay = ldtDate.substr( 0 , 2 );
lstrMonth = ldtDate.substr( 3 , 2 );
lstrYear = ldtDate.substr( 6 , 4 );
lstrMonthinword = month [lstrMonth];
lstrDate = lstrDay + - + lstrMonthinword + - + lstrYear;
return lstrDate;
}
所有月份都正确转换为单词,除了'' 08''和''09'';
即08-08-2012返回08-undefined-2012或08 --- 2012;
但是03-11-2012正在正确转换为03-NOV-2012;
任何提示/建议来解决这个问题:)
解决方案
改变这一行:
lstrMonthinword =月[lstrMonth];
进入这一行:
lstrMonthinword = month [parseFloat(lstrMonth)];
你有没有检查过,...
在通过日期时 08-08-2012 它是没有被转换为 8-8-2012 因为在这种情况下它将以错误的方式拆分字符串所以,月份转换将是错误的
一些链接...使用javascript设置日期格式
http://blog.stevenlevithan.com/archives/date-time-format [ ^ ]
http://www.w3schools .com / jsref / jsref_obj_date.asp [ ^ ]
JavaScript日期格式 [ ^ ]
http://stackoverflow.com/questions/ 1056728 /格式化j-date-in-javascript [ ^ ]
快乐编码!
:)
当你通过08到月[08]时,它会将''08'转换为八进制,这就是你未定义的原因
lstrMonthinword = month [ parseInt (lstrMonth, 10 )];
Hi All,
I need to convert the month in number to read month in Words.
I made a javascript function to convert that like below :
function convert(mycontrolclientID)
{
var ldtDate=mycontrol.value;
var month=new Array();
var lstrDay,lstrMonth,lstrYear,lstrMonthinword=1,lstrDate;
month = ["",'JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'];
lstrDay = ldtDate.substr(0,2);
lstrMonth = ldtDate.substr(3,2);
lstrYear = ldtDate.substr(6,4);
lstrMonthinword = month[lstrMonth];
lstrDate = lstrDay + "-" + lstrMonthinword + "-" + lstrYear;
return lstrDate;
}
All Months are properly converting to Words except ''08'' and ''09'';
i.e 08-08-2012 returning 08-undefined-2012 or 08---2012;
But 03-11-2012 is converting correctly to 03-NOV-2012;
Any Tips/Suggestions to fix this :)
解决方案
Hi,
Change this line:
lstrMonthinword = month[lstrMonth];
Into this line:
lstrMonthinword = month[parseFloat(lstrMonth)];
have you checked that,...
when passing date 08-08-2012 it is not being converted as 8-8-2012 because in this case it will split string in wrong way so, month conversion will be wrong
some links... for set date formats using javascript
http://blog.stevenlevithan.com/archives/date-time-format[^]
http://www.w3schools.com/jsref/jsref_obj_date.asp[^]
JavaScript Date Format[^]
http://stackoverflow.com/questions/1056728/formatting-a-date-in-javascript[^]
Happy Coding!
:)
when you are pass 08 to month[08] it will convert ''08'' to octal that''s why you getting undefined
lstrMonthinword = month[parseInt(lstrMonth, 10)];
这篇关于转换“NUMBER中的月份” in to“Month in WORD”:22-09-2012 - > 22-SEP-2012的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文