在AS3和MXML中格式化日期
在项目中,我们用到格式化系统当前日期,格式化指定日期等.都是利用DateFormatter来实现的
本例分别演示如何在AS3和MXML中利用DateFormatter按照指定格式,格式化日期显示
<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"><mx:Script> <![CDATA[ import mx.formatters.*; [Bindable] private var time:Date=new Date(); private function TestDateTimeToString():void { var fr:DateFormatter=new DateFormatter(); fr.formatString="YYYY-MM-DD JJ:NN:SS"; currentTimeAS3.text=fr.format(time); } ]]> </mx:Script> <mx:DateFormatter id="dateFormat" formatString="YYYY-MM-DD JJ:NN:SS"/> <mx:Panel width="100%" height="100%"> <mx:Label id="currentTimeText" text="当前日期:"/> <mx:Label id="currentTime" text="{dateFormat.format(time)}"/> <mx:Button label="调用AS3转换当前日期" click="TestDateTimeToString()"/> <mx:Label id="currentTimeAS3" text="现在的时间还没有被转换" /> </mx:Panel> </mx:Application>