<?xml version="1.0"?>
<!-- Simple example to demonstrate the Halo DateField control. -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import spark.formatters.DateTimeFormatter;
// Event handler for the Halo DateField change event.
private function dateChanged(date:Date):void {
//var date:Date = new Date();
if (date == null) {
selection.text = "Date selected: ";
} else {
selection.text = "Date selected: " + date.getFullYear().toString() + '/' + (date.getMonth()+1).toString() + '/' + date.getDate();
}
}
private function formatDateToStringDate(obj:Object, column:GridColumn):String
{
var dateTimeFormatter:DateTimeFormatter = new DateTimeFormatter();
dateTimeFormatter.dateTimePattern = "yyyy-MM-dd";
var date_time:Date = obj.toString();//obj.toString()代表obj对象的属性
var date_text:String = dateTimeFormatter.format(date_time);
return date_text;
}
]]>
</fx:Script>
<fx:Declarations>
<mx:DateFormatter id="df"/>
</fx:Declarations>
<s:Panel title="Halo DateField Control Example"
width="75%" height="75%"
horizontalCenter="0" verticalCenter="0">
<s:VGroup left="10" right="10" top="10" bottom="10">
<s:Label width="100%" color="blue"
text="Select a date in the Halo DateField control. Select it again to clear it."/>
<!--1-->
<s:Label text="Basic Halo DateField:"/>
<mx:DateField id="dateField1" yearNavigationEnabled="true"
change="dateChanged((DateField)(event.target).selectedDate)" />
<s:Label id="selection" color="blue" text="Date selected:" />
<mx:Spacer height="30" />
<s:Label text="Disable dates on or before June 1, 2006."/>
<mx:DateField id="dateField2" yearNavigationEnabled="true"
disabledRanges="{[ {rangeEnd: new Date(2006, 5, 1)} ]}" />
<s:Label color="blue" text="Date selected: {df.format(dateField2.selectedDate)}"/>
<s:Spacer height="30"/>
<!--2-->
<mx:DateField id="d502_12" yearNavigationEnabled="true" selectedDate="{new Date()}" width="128" dayNames='["日","一","二","三","四","五","六"]'
monthNames='["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"]'
formatString="YYYY-MM-DD"/>
<s:Spacer height="30"/>
<!--获取日期格式-->
<s:DataGrid>
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="time" headerText="DATE" labelFunction="formatDateToStringDate"/>
</s:ArrayList>
</s:columns>
</s:DataGrid>
</s:VGroup>
</s:Panel>
</s:Application>