Ver Mensaje Individual
  #3  
Antiguo 03-08-2010
rrf rrf is offline
Miembro
 
Registrado: ago 2003
Ubicación: S/C Tenerife, España
Posts: 454
Reputación: 21
rrf Va por buen camino
Smile

Hola.
Aquí tienes una posible solución.
Lo probé y funcionó bien.

Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
var
  hh1, mm1, ss1, hh2, mm2, ss2, hh3, mm3, ss3, nada : word ;
  TotalSegundos : integer ;
  aa, bb : string ;
  Tiempo1, Tiempo2, TFinal : TDateTime ;
begin

  aa := '20-15-03' ;
  hh1 := strtoint ( copy ( aa, 1, 2 ) ) ;
  mm1 := strtoint ( copy ( aa, 4, 2 ) ) ;
  ss1 := strtoint ( copy ( aa, 7, 2 ) ) ;
  Tiempo1 := EncodeTime( hh1, mm1, ss1, 0 ) ;

  bb := '22-18-09' ;
  hh2 := strtoint ( copy ( bb, 1, 2 ) ) ;
  mm2 := strtoint ( copy ( bb, 4, 2 ) ) ;
  ss2 := strtoint ( copy ( bb, 7, 2 ) ) ;
  Tiempo2 := EncodeTime( hh2, mm2, ss2, 0 ) ;

  Tfinal  := tiempo2 - Tiempo1 ;

//ShowMessage( TimeToStr ( Tiempo1) +#13+ TimeToStr ( Tiempo2) +#13+ TimeToStr ( Tfinal)  );

  DecodeTime( Tfinal, hh3, mm3, ss3, nada );
  TotalSegundos := hh3 * 3600 + mm3 * 60 + ss3 ;
  ShowMessage( 'Segundos: '+ inttostr ( TotalSegundos )  );

end;

Está probado en Delphi 7, aunque creo que funcionará bien en otras versiones.

Le puse valores fijos a los string (aa, bb) para la prueba, pero se puede adaptar para que funcione como una función que recibe los 2 string como parámetros y devuelve el número de segundos.

Salu2.

Ramón.
Responder Con Cita