【发布时间】:2011-06-30 09:09:26
【问题描述】:
我在 Flex 中使用 MX DateField 控件,并希望将日期显示为 2011 年 7 月 1 日或 2011 年 7 月 1 日。有人知道该怎么做吗?我尝试将 formatString 设置为“DD MMM YYYY”,但没有成功。
【问题讨论】:
标签: apache-flex flex4.5 datefield
我在 Flex 中使用 MX DateField 控件,并希望将日期显示为 2011 年 7 月 1 日或 2011 年 7 月 1 日。有人知道该怎么做吗?我尝试将 formatString 设置为“DD MMM YYYY”,但没有成功。
【问题讨论】:
标签: apache-flex flex4.5 datefield
这行得通:
<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 属性不能正常工作。 我可以确认它没有按预期工作。
干杯
【讨论】:
dateToString() 和 stringToDate() 并没有像 <mx:DateFormatter/> 元素中使用的代码那样功能齐全。此错误还意味着您必须在更改labelFunction() 时将parseFunction() 设置为null(请参阅错误报告)。
我会使用这样的东西:
<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" />
希望这会有所帮助。
【讨论】: