前加0我有这样一个日期:我有改变月份成数的函数,但我想了一个月的数量
19/août/2016 (août = august)
而且我有以下功能月份,它就变成数量:
function swapMonthForNumber(str:String):String {
//do the same line of code for every item in the array
for(var i:int=0;i<months.length;i++){
//i is the item, which is 0 based, so we have to add 1 to make the right month number
str = str.replace(months[i],String(+i+1));
}
//return the updated string
return str;
}
str = swapMonthForNumber(mySharedObject.data.theDate);
trace("Php will use this date :"+str);
所以str
将19/8/2016
,但我想str
是19/08/2016
(添加0
前8
)。
我该怎么做?
是什么'字符串(+ I + 1)'做什么?我以前从来没有见过。 –
您可能要检查月份是否小于10,如果是这样,则通过执行“0”+ String(i + 1)来为“String(i + 1)”预留一个“0” '(不确定'+是否是AS3中的连接运算符,但我认为是)。 –
@JonnyHenly在(+ i + 1)中领先的+是多余的,因为它不会改变i的符号。 – dxb