据我所知,可以将特定于本地的ResourceBundle与DateFormatters结合使用,以根据区域设置格式化日期。但是,这是一个手动过程 - 是否有自动方法来执行此操作或为应用程序设置默认值?
例如,在Java中,只需设置区域设置,所有日期将自动以dd / mm / yy或mm / dd / yy格式显示。在Flex中,默认日期输出将始终采用美国格式,除非另行手动格式化。我正在寻找一种更接近Java功能的方法。
答案 0 :(得分:1)
我最近使用flah.globalization类做了这个: 看到它有关获取语言环境等的信息。 http://www.adobe.com/devnet/flashplayer/articles/flash_globalization_package.html 这是我的代码:
记得调用init();在创作完成!
<fx:Script>
<![CDATA[
import flash.globalization.DateTimeFormatter;
import flash.globalization.DateTimeStyle;
import flash.globalization.StringTools;
import mx.collections.ArrayCollection;
import spark.events.IndexChangeEvent;
[Bindable]
private var listColl:ArrayCollection;
private var localeList:Array = new Array("en-US", "fr-FR", "es-ES","ja-JP", "hi-IN","ru-RU");
private var country:String;
private function init():void{
// set the dp for drop down;
listColl = new ArrayCollection(localeList);
country = localeList[0];
}
private function doDateLabel(item:Date):String {
trace("input = " + item);
if(item != null) {
var locale:String = country;
if(locale != null){
var dtf:DateTimeFormatter = new DateTimeFormatter(locale);
dtf.setDateTimeStyles(DateTimeStyle.SHORT, DateTimeStyle.NONE);
/*
DateTimeSyle.MEDIUM
DateTimeSyle.LONG
*/
var shortDate:String = dtf.format(item);
trace(shortDate + " (" + dtf.getDateTimePattern() + ")");
}
}
return shortDate;
}
protected function dropDownList_changeHandler(evt:IndexChangeEvent):void {
country = countryList.selectedItem;
}
]]>
</fx:Script>
<s:HGroup width="100%" height="100%" gap="20" top="50" left="50">
Hope that's what you were after
<mx:DateField id="begin" width="200"
showToday="true"
labelFunction="doDateLabel"
parseFunction="null"/>
<s:DropDownList id="countryList"
requireSelection="true" prompt="Please select an Country"
horizontalCenter="0" top="20" dataProvider="{listColl}"
change="dropDownList_changeHandler(event);">
</s:DropDownList>
</s:HGroup>
答案 1 :(得分:0)
查看toLocaleString和toLocaleTimeString
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Date.html#toLocaleString()
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Date.html#toLocaleTimeString()
答案 2 :(得分:0)
Flash Player 10.1的一项功能放在flash.globalization包
中The flash.globalization package in Flash Player: Cultural diversity without complexity