热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

dateField添加时分秒显示(优化)

在网上找的,进行优化完善myChooseTimepackagecom.gps.view.component.nmsDateFiled{importflash.

在网上找的,进行优化完善...

myChooseTime

package com.gps.view.component.nmsDateFiled
{import flash.events.Event;import mx.containers.HBox;import mx.containers.Panel;import mx.controls.ComboBox;import mx.controls.Label;import mx.formatters.DateFormatter; public class myChooseTime extends Panel{public var nmsHour:ComboBox;public var nmsMinute:ComboBox;public var nmsSeconds:ComboBox;public var timesBox:HBox ;public var lblMinute:Label;public var lblSeconds:Label;private var chooseDate:Date;private var hDataSource:Array = ["00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"];private var msDataSource:Array = ["00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59"];private var backGroundColor:Array = ["white","white","white","white"];public function myChooseTime(){super();this.width = 200;this.height = 25;this.setStyle("headerHeight", 0); this.setStyle("borderStyle", "solid"); this.setStyle("borderThicknessLeft", 1); this.setStyle("borderThicknessRight", 1); this.setStyle("cornerRadius", 0); timesBox=new HBox(); timesBox.setStyle("horizontalGap", "0"); timesBox.setStyle("verticalGap", "0"); timesBox.setStyle("verticalAlign", "middle"); timesBox.setStyle("backgroundColor", "white"); timesBox.setStyle("paddingLeft", "5"); timesBox.setStyle("paddingBottom", "2"); timesBox.setStyle("borderStyle", "none"); }protected override function childrenCreated():void{super.createChildren(); if (!nmsHour) { nmsHour=new ComboBox(); nmsHour.width=55; nmsHour.height=18;nmsHour.dataProvider=hDataSource; nmsHour.setStyle("cornerRadius", "0"); nmsHour.setStyle("fontSize", "10"); nmsHour.setStyle("fillColors", backGroundColor); nmsHour.addEventListener("change", updateValue); nmsHour.editable = false;} if (!lblMinute) { lblMinute=new Label(); lblMinute.width=10; lblMinute.text=":"; } if (!nmsMinute) { nmsMinute=new ComboBox(); nmsMinute.width=55; nmsMinute.height=18; nmsMinute.dataProvider=msDataSource; nmsMinute.setStyle("fontSize", "10"); nmsMinute.setStyle("cornerRadius", "0"); nmsMinute.setStyle("fillColors", backGroundColor); nmsMinute.addEventListener("change", updateValue); nmsMinute.editable = false;} if (!lblSeconds) { lblSeconds=new Label(); lblSeconds.width=10; lblSeconds.text=":"; } if (!nmsSeconds) { nmsSeconds=new ComboBox(); nmsSeconds.width=55; nmsSeconds.height=18; nmsSeconds.setStyle("fontSize", "10"); nmsSeconds.setStyle("cornerRadius", "0"); nmsSeconds.setStyle("fillColors", backGroundColor); nmsSeconds.dataProvider=msDataSource; nmsSeconds.addEventListener("change", updateValue); nmsSeconds.editable = false;} timesBox.addChild(nmsHour); timesBox.addChild(lblMinute); timesBox.addChild(nmsMinute); timesBox.addChild(lblSeconds); timesBox.addChild(nmsSeconds); this.addChild(timesBox); this.parent.addEventListener("change", updateValue);setTimesValue();}private function setTimesValue():void{var dateChooser:myDateChooser=this.parent as myDateChooser; var dateField:myDateFiled=dateChooser.owner as myDateFiled;var timesStr:String = dateField.text;
// var timeStr:String = timesStr.substring(timesStr.indexOf(" ")+1,timesStr.length);
// var timeArray:Array = timeStr.split(':');var strDate:Date = DateFormatter.parseDateString(timesStr);//格式化string到datenmsHour.selectedIndex = int(strDate.hours);nmsMinute.selectedIndex = int(strDate.minutes); nmsSeconds.selectedIndex = int(strDate.seconds);dateChooser.displayedYear = int(strDate.fullYear);dateChooser.displayedMonth = int(strDate.month);dateField.selectedDate = DateFormatter.parseDateString(timesStr.substring(0,timesStr.indexOf(" ")));}//当下拉时分秒下拉框的值改变的时候,动态修改日期控制的textinput的显示值 private function updateValue(event:Event):void { if (this.parent is myDateChooser) { var dateChooser:myDateChooser=this.parent as myDateChooser; var dateField:myDateFiled=dateChooser.owner as myDateFiled; //若没有选择日期则默认为已经选中的日期if(dateChooser.selectedDate == null){var timesStr:String = dateField.text;chooseDate = DateFormatter.parseDateString(timesStr.substring(0,timesStr.indexOf(" ")));//格式化string到date}else{chooseDate = dateChooser.selectedDate;}if (dateChooser.owner is myDateFiled) { dateField.selectedDate =chooseDate;dateField.labelFunction=formatDateTemp; } } } //日期显示格式 private function formatDateTemp(date:Date):String {if (date == null) { date=chooseDate; } date.hours=(Number)(nmsHour.selectedItem); date.minutes=(Number)(nmsMinute.selectedItem); date.seconds=(Number)(nmsSeconds.selectedItem); var df:DateFormatter=new DateFormatter(); df.formatString="YYYY-MM-DD JJ:NN:SS"; var times:String=df.format(date); return times; } }
}

package com.gps.view.component.nmsDateFiled
{import mx.controls.DateChooser;public class myDateChooser extends DateChooser{public var myTimes:myChooseTime;public function myDateChooser(){super();this.width = 200;this.height = 200;this.setStyle("fontSize", "12");this.yearNavigationEnabled = true;this.showToday = false;myTimes = new myChooseTime();myTimes.x = 0;myTimes.y = 200;}protected override function createChildren():void{super.createChildren();addChild(myTimes);}}
}

myDateFiled

package com.gps.view.component.nmsDateFiled
{import flash.events.KeyboardEvent;import flash.ui.Keyboard;import mx.controls.DateField;import mx.core.ClassFactory;import mx.events.CalendarLayoutChangeEvent;import mx.formatters.DateFormatter; public class myDateFiled extends DateField{public function myDateFiled(){super();this.formatString = "yyyy-mm-dd";this.dayNames = ["日","一","二","三","四","五","六"];this.monthNames = ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"];this.dropdownFactory = new ClassFactory(myDateChooser);this.labelFunction=formatDate; this.editable=false; this.addEventListener(CalendarLayoutChangeEvent.CHANGE, showDateChooser); this.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown); // this.addEventListener("change",setSelectedDate);}private function formatDate(currentDate:Date):String{var dateFormatter:DateFormatter = new DateFormatter();dateFormatter.formatString = "YYYY-MM-DD JJ:NN:SS";currentDate = new Date();var timeStr:String = dateFormatter.format(currentDate);return timeStr;}// private function setSelectedDate():void
// {
// this.selectedDate = DateFormatter.parseDateString(this.text.substring(0,this.text.indexOf(" ")))
// }private function showDateChooser():void{this.open();
// this.selectedDate = DateFormatter.parseDateString(this.text.substring(0,this.text.indexOf(" ")));}private function handleKeyDown(event:KeyboardEvent):void{if (event.keyCode == Keyboard.ENTER) { var tempNmsDateChooser:myDateChooser=this.dropdown as myDateChooser; tempNmsDateChooser.myTimes.nmsHour.close(); tempNmsDateChooser.myTimes.nmsMinute.close(); tempNmsDateChooser.myTimes.nmsSeconds.close(); } }}
}

 


转:https://www.cnblogs.com/wyh167/archive/2012/11/15/2771157.html



推荐阅读
author-avatar
菲菲不停2502898155
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有