【发布时间】:2016-08-18 22:23:29
【问题描述】:
我有这样的约会:
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(在8 之前添加0)。
我该怎么做?
【问题讨论】:
-
String(+i+1)是做什么的?我以前从未见过。 -
您可能想要检查月份是否小于 10,如果是,则通过执行
"0" + String(i+1)将"0"添加到String(i+1)(不确定+是否为AS3 中的连接运算符,但我认为是)。 -
@JonnyHenly 在 (+i+1) 中,前导 + 是多余的,因为它不会改变 i 的符号。
-
@dene : String(+i+1) 未编辑,但在我认为的原始消息中由 user5870211 使用。但可以肯定的是它是多余的;)
标签: actionscript-3