ITeye博客

在AS3和MXML中格式化日期

cloud21 · 2010-08-04 15:57 · Flex · Web前端 · Markdown

在项目中,我们用到格式化系统当前日期,格式化指定日期等.都是利用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>


评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。