[Resolvido]Calculo de horas em flex4

2 respostas
V

Ola a todos,

To precisando fazer o calculo de tempo que dura o processamento de meu remotObject desde que eu chamo o metodo no java ate ele chegar no onResult.Ate ai tranquilo faço na hora de chama o metodo java do remot um horaInicial = data.getTime() e no onResult um tempo = data.getTime() - horaInicial ate ai blz,mas na hora de converter para um formato legivel HH:MM:SS meu DateFormatter nao formata,ele fica 0,alguem tem alguma soluçao?

//MINHA CHAMADA AO JAVA
var data:Date = new Date();
					HoraInicioComp = data.getTime();
					
					if(chkTabela.selected == true) {
						
						
						var re:mx.rpc.remoting.RemoteObject = new mx.rpc.remoting.RemoteObject("Main"); // coloca o id do remoting-config.xml
						re.addEventListener(ResultEvent.RESULT,onResult);
						re.addEventListener(FaultEvent.FAULT,onFault);
						re.showBusyCursor = true;
						re.main(porta,host,nomeCon,usuario,senha,path,owner);
																	
					}
//MEU RESULT FAZENDO O CALCULO
private function onResult(event:ResultEvent):void{
				listNC = event.result as ArrayCollection;
				Alert.show("Tabelas Comparadas Com Sucesso!","Sucesso!");
				var data:Date = new Date();
				var tempoFinal:Number = data.getTime();
				
				tempoFinalComparacao = tempoFinal - HoraInicioComp;
				
				ctrTempo.visible = true;
				lblTmpCmp.visible = true;
				lblTmpCmp.text = "Tempo Total de Comparação: "+formatadorHora.format(tempoFinalComparacao);
				
			}
//MEU FORMATADOR
<mx:DateFormatter id="formatadorHora" formatString="JJ:NN:SS"/>

2 Respostas

Ivan_Alves

O DateFormatter só formata tipo Date e não do tipo Number mais você pode fazer um método para te retornar isso por exemplo

//considerando que a cada 1000 milisegundos equivale a 1 segundo então
public function retornarHoraFormatada(tempo:Number):String{
	//var milesegundos:int = tempo % 1000;
	var segundos:int = (tempo / 1000) % 60; 
	var minutos:int = (tempo / 1000 / 60) % 60;
	var horas:int = 0;
				
	return "Foram gastos "+horas+" horas, "+minutos+" minutos e "+segundos+" segundos!";
}

ou também retornar uma tipo date e depois usar seu objeto formatador para formatala por exemplo

public function retornarHoraFormatada(tempo:Number):Date{  
    var milesegundos:int = tempo % 1000;  
    var segundos:int = (tempo / 1000) % 60;   
    var minutos:int = (tempo / 1000 / 60) % 60;  
    var horas:int = (tempo / 1000 / 60 / 60) % 24;  
    
    var dataRetorno:Date = new Date();
    
    dataRetorno.setHours(horas, minutos, segundos, milesegundos);
       
    return dataRetorno;  
}

depois é só chamar normal esse método passando o tempo como argumento

flw

V

Pois eh eu nao sabia dateFormatter nao consegue formatar a data do tipo Number,fiz isso e realmente deu certo :smiley:

vlw

Criado 30 de junho de 2011
Ultima resposta 2 de jul. de 2011
Respostas 2
Participantes 2