我在 Flex 中使用 MX DateField 控件并希望将日期显示为 2011 年 7 月 1 日或 2011 年 7 月 1 日。有人知道该怎么做吗?我尝试将 formatString 设置为“DD MMM YYYY”,但没有成功。
问问题
4013 次
2 回答
4
这有效:
<fx:Declarations>
<mx:DateFormatter id="myDf" formatString="DD MMM YYYY"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
private function formatDate(date:Date):String{
return myDf.format(date);
}
]]>
</fx:Script>
<mx:DateField id="dateField" labelFunction="formatDate" />
在http://livedocs.adobe.com/flex/3/html/help.html?content=controls_12.html的 LiveDocs 中找到它
但是,这并不能解释为什么组件上的 formatString 属性不能正常工作。我可以确认它没有按预期工作。
干杯
于 2011-06-30T09:48:46.263 回答
0
我会使用这样的东西:
<mx DateField id = "dateField"
dayNames ="["S", "M", "T", "W", "T", "F", "S"]"
monthNames="["January", "February", "March", "April", "May",
"June", "July", "August", "September", "October",
"November", "December"]" />
既然你提到了 3 个字符的月份名称,这是一个很好的例子。当然,如果您不需要日期名称,请删除该行。
<mx DateField id = "dateField"
dayNames ="["S", "M", "T", "W", "T", "F", "S"]"
monthNames="["Jan", "Feb", "Mar", "Apr", "May",
"Jun", "Jul", "Aug", "Sep", "Oct",
"Nov", "Dec"]"
formatString = "DD MMM YYY" />
希望这可以帮助。
于 2012-05-01T15:29:18.907 回答