<?xml version="1.0" encoding="utf-8"?> <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ import mx.formatters.DateFormatter; import flash.utils.Timer; import flash.events.TimerEvent; private function init():void { var timer:Timer = new Timer(1000); timer.addEventListener(TimerEvent.TIMER, this.resetNow); timer.start(); } private function resetNow(event:TimerEvent):void { // 获取登录时间和日期 var dateFormatter:DateFormatter = new DateFormatter(); dateFormatter.formatString = "YYYY年MM月DD日"; var time:String = new Date().toLocaleTimeString(); var date:String = dateFormatter.format(new Date()); this.date.text = date; this.clock.text = time; } ]]> </mx:Script> <mx:Text id="clock" text="" creationComplete="this.init()" height="20" color="#FFFFFF"/> <mx:Text id="date" text="" creationComplete="this.init()" height="20" color="#FFFFFF"/> </mx:HBox>