日時にカスタム コンポーネントを使用しています。これは 12 時間と午前/午後の形式です。数値ステッパーで 24 時間形式を表示する必要があり、午前/午後を無効にする必要があります。何か考えがありますか?
ここに私のコードがあります
<mx:Script>
<![CDATA[
[Bindable] private var _selectedDate:Date = new Date();
[Bindable] [Inspectable(defaultValue='5', category="Other", enumeration="1,5,10,15,30")]
public var minuteIncrement:int = 1;
public function get selectedDate():Date
{
var rtnVal:Date = null;
if(this.date.text != "")
{
this.validateNow();
rtnVal = this._selectedDate;
}
return rtnVal;
}
private function getVisible(flg:Boolean):void
{
if(!flg)
{
//Invisible
hours.visible = false;
lbl.visible = false;
minutes.visible = false;
am.visible = false;
pm.visible = false;
}
else
{
//Visible
hours.visible = true;
lbl.visible = true;
minutes.visible = true;
am.visible = true;
pm.visible = true;
}
}
public function clearDate():void
{
selectedDate = new Date();
date.selectedDate = null;
getVisible(false);
}
[Bindable]
public function set selectedDate(value:Date):void
{
if(value != null)
{
this._selectedDate = value
this.date.selectedDate = this._selectedDate
if(value.getHours() >= 12)
{
this.ampm.selectedValue = 2;
}
else
{
this.ampm.selectedValue = 1;
}
if(value.getHours() < 13 )
this.hours.value = value.getHours()
else
this.hours.value = value.getHours() - 12
if(value.getHours() == 0)
this.hours.value = 12;
this.minutes.value = value.getMinutes()
this.validateNow();
getVisible(true);
}
else
{
clearDate();
}
}
override public function validateProperties():void
{
super.validateProperties();
}
public function handleChange():void
{
getVisible(true);
if(this.date.text != "")
{
var militaryHours:int = hours.value;
if(ampm.selectedValue == 2 && hours.value != 12)
militaryHours = hours.value+12;
else if(ampm.selectedValue == 1 && hours.value == 12)
militaryHours = 0;
var selDate:Date = this.date.selectedDate;
var date:Date = new Date(
selDate.getFullYear(),
selDate.getMonth(),
selDate.getDate(),
militaryHours,
minutes.value)
this.selectedDate = date;
this.invalidateProperties();
this.validateNow();
this.dispatchEvent(new Event("change"));
}
}
]]>
</mx:Script>
<mx:DateField id="date" selectedDate="{new Date()}" change="handleChange()" formatString="DD/MM/YYYY"/>
<mx:Spacer width="10"/>
<mx:NumericStepper id="hours" minimum="1" maximum="12" stepSize="1" width="40" change="handleChange()" valueCommit="handleChange()" textAlign="center"/>
<mx:Label id="lbl" text=":" textAlign="center"/>
<mx:NumericStepper id="minutes" minimum="0" maximum="59" stepSize="{minuteIncrement}" change="handleChange()" valueCommit="handleChange()" textAlign="center" width="40"/>
<mx:Spacer width="10"/>
<mx:RadioButtonGroup id="ampm" selectedValue="1" change="this.handleChange()"/>
<mx:RadioButton id="am" value="1" label="AM" group="{ampm}"/>
<mx:RadioButton id="pm" value="2" label="PM" group="{ampm}"/>
事前にxxxxxxxxxに感謝します!!