基于Air的日期计算器
很简单的一个程序,计算从某天到某天一共经历了多少年,多少月,多少日,多少周. 或从某天在某年,某月,某周,某日之后是哪天
<?xml version="1.0" encoding="utf-8"?> <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="882" height="372" title="DateCounter by Zac@GoldG.net(Zhengliang Guo)"> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <fx:Script> <![CDATA[ private function ftChanged():void { if(fromDate.selectedDate && toDate.selectedDate){ var gapTime:Number; gapTime = (toDate.selectedDate.getTime() - fromDate.selectedDate.getTime()) / 1000 / 3600 / 24; dd.text = (gapTime).toString(); ww.text = (gapTime/7.0).toString(); yy.text = (gapTime/365.0).toString(); mm.text = (int(gapTime/365) *12 + (toDate.selectedDate.getMonth() - fromDate.selectedDate.getMonth())).toString(); } } private function midChanged(str:String):void { dstY.text = (startDate.selectedDate.getFullYear()).toString(); dstM.text = (startDate.selectedDate.getMonth()+1).toString(); dstD.text = (startDate.selectedDate.getDate()).toString(); if(startDate.selectedDate) { var midTime:Number; if(str == 'y') { midTime = Number(midY.text); resetField2(); midY.text = midTime.toString(); dstY.text = (startDate.selectedDate.getFullYear() + midTime).toString(); } else if(str == 'm') { midTime = Number(midM.text); resetField2(); midM.text = midTime.toString(); if(((startDate.selectedDate.getMonth() + 1 + midTime))>12) { dstY.text = (Number(dstY.text) + int((startDate.selectedDate.getMonth() + 1 + midTime)/12)).toString(); dstM.text = ((startDate.selectedDate.getMonth() + 1 + midTime) % 12).toString(); } else{ dstM.text = (startDate.selectedDate.getMonth() + 1 + midTime).toString(); } } else if(str == 'w') { midTime = Number(midW.text); resetField2(); midW.text = midTime.toString(); var tarDate:Date = new Date(); tarDate.setTime(startDate.selectedDate.getTime() + (midTime * 7 * 24 * 3600 * 1000)); dstY.text = (tarDate.getFullYear()).toString(); dstM.text = (tarDate.getMonth() + 1).toString(); dstD.text = (tarDate.getDate()).toString(); } else if(str == 'd') { midTime = Number(midD.text); resetField2(); midD.text = midTime.toString(); var tarDate:Date = new Date(); tarDate.setTime( startDate.selectedDate.getTime() + (midTime * 24 * 3600 * 1000)); dstY.text = (tarDate.getFullYear()).toString(); dstM.text = (tarDate.getMonth() + 1).toString(); dstD.text = (tarDate.getDate()).toString(); } else if(str == 'c') { resetField2(); } } } private function resetField2():void { midY.text = "0"; midM.text = "0"; midW.text = "0"; midD.text = "0"; } ]]> </fx:Script> <mx:DateChooser id="fromDate" x="27" y="66" change="ftChanged()" showToday="false" /> <mx:DateChooser id="toDate" x="211" y="66" change="ftChanged()" showToday="false" /> <s:Label x="87" y="20" text="From" fontSize="25"/> <s:Label x="276" y="19" text="To" fontSize="25"/> <s:Label x="22" y="280" text="Days" fontSize="20"/> <s:Label x="22" y="319" text="Weeks" fontSize="20"/> <s:Label x="206" y="281" text="Month" fontSize="20"/> <s:Label x="206" y="316" text="Year" fontSize="20"/> <s:Label id="dd" x="96" y="281" text="d"/> <s:Label id="ww" x="96" y="320" text="w"/> <s:Label id="mm" x="272" y="285" text="m"/> <s:Label id="yy" x="272" y="320" text="y"/> <s:Panel x="433" y="10" width="433" height="328" title="Date To Time"> <s:TextInput x="277" y="23" text="0" id="midY" change="midChanged('y')"/> <s:TextInput x="277" y="53" text="0" id="midM" change="midChanged('m')"/> <s:TextInput x="277" y="84" text="0" id="midW" change="midChanged('w')"/> <s:TextInput x="277" y="114" text="0" id="midD" change="midChanged('d')"/> <s:Label id="myy" x="225" y="28" text="Years"/> <s:Label id="mmm" x="225" y="59" text="Month"/> <s:Label id="mww" x="225" y="90" text="Weeks"/> <s:Label id="mdd" x="225" y="119" text="Days"/> <mx:DateChooser id="startDate" x="10" y="10" change="midChanged('c')" showToday="false"/> <s:Label x="47" y="236" text="0000" fontSize="35" id="dstY"/> <s:Label x="158" y="236" text="00" fontSize="35" id="dstM"/> <s:Label x="225" y="236" text="00" fontSize="35" id="dstD"/> </s:Panel> </s:WindowedApplication> |
很麻烦… 真有人需要的花, 自己看看吧, 不知道能不能帮上….
南无阿弥陀佛 南无本师释迦牟尼佛 南无药师琉璃光如来