在Flex中,我们有的时候需要用到这样的日期格式:2008年08月21日 星期四,但是在Flex的日期格式化中,是没有这种format的,如何事项呢,下面有一个例子,可以帮助你
// private var myData1=new Date();
public function getChinaTimeDate(nowDate:Date):String
{
var rtnStr:String = "";
// 格式化函数
var myDateFormatXQ = new DateFormatter();
var testY:String = nowDate.getFullYear().toString();
var testM:String = (nowDate.getMonth()+1).toString();
var testD:String = nowDate.getDate().toString();
var weekStr = "";
var ymd:String = "";
// 定义日期格式
myDateFormatXQ.formatString="EEEE";
weekStr = myDateFormatXQ.format(nowDate);
switch(weekStr)
{
case "Monday":
weekStr = "星期一";
break;
case "Tuesday":
weekStr = "星期二";
break;
case "Wednesday":
weekStr = "星期三";
break;
case "Thursday":
weekStr = "星期四";
break;
case "Friday":
weekStr = "星期五";
break;
case "Saturday":
weekStr = "星期六";
break;
case "Sunday":
weekStr = "星期日";
break;
}
rtnStr = testY+"年"+testM+"月"+testD+"日";
rtnStr = "1今天是:" + rtnStr + " " +weekStr;
mx.controls.Alert.show(testM);
return rtnStr;
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
在项目中,我们用到格式化系统当前日期,格式化指定日期等.都是利用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>
http://www.blogjava.net/rainwindboys/archive/2008/08/29/225614.html