<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="defaultYm()"> <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.states.SetStyle; import flash.sampler.NewObjectSample; private function defaultYm():void{ var nowDate:Date = new Date(); var nowyear:String = nowDate.getFullYear().toString(); var nowmonth:String = (nowDate.getMonth()+1).toString().length == 1?"0"+(nowDate.getMonth()+1).toString():(nowDate.getMonth()+1).toString(); var lastdaysOfMonth:String = daysOfMonth(nowyear+nowmonth); Alert.show("当月最后一天"+lastdaysOfMonth); } function daysOfMonth(Month):String{ var currentMonth=new Date(Month.substring(0,4),Month.substring(4,6),1); var lastMonth=new Date(Month.substring(0,6)-1,1); var diffDays=currentMonth-lastMonth; return ""+(diffDays/( 24 * 60 * 60 * 1000)); } ]]> </mx:Script> </mx:Application>