I have a problem with Time...

Hi... my problem is that I need to compare two Times, but I don't know wath is wrong in my code... I read a Time from a String, I convert that String in Date, and I transfor this Date in Time, to compare with another Time... but It don't work...

My code is:publiclong Valor_Minutos(long Minutos,long Ini,long Fin,int Mesa){

Connection conec;

Statement state;

ResultSet rec;

String Horas_1, Horas_2, Horas_3;

int Valor_1, Valor_2, Valor_3;

long Valor_Total;

java.util.Date Fecha, Fecha_1_1, Fecha_1_2, Fecha_2_1, Fecha_2_2, Fecha_3_1, Fecha_3_2;

java.sql.Time Hr_1_1, Hr_1_2, Hr_2_1, Hr_2_2, Hr_3_1, Hr_3_2, Hr_Ini, Hr_Fin;

SimpleDateFormat sdf =new SimpleDateFormat("HH:mm:ss");

Fecha =new java.util.Date();

Fecha.setTime(Ini);

Hr_Ini =new java.sql.Time(Fecha.getTime());

Fecha.setTime(Fin);

Hr_Fin =new java.sql.Time(Fecha.getTime());

Horas_1 = Horas_2 = Horas_3 =null;

Valor_1 = Valor_2 = Valor_3 = 0;

rec =null;

Fecha_1_1 = Fecha_1_2 = Fecha_2_1 = Fecha_2_2 = Fecha_3_1 = Fecha_3_2 =null;

Hr_1_1 = Hr_1_2 = Hr_2_1 = Hr_2_2 = Hr_3_1 = Hr_3_2 =new java.sql.Time(0);

Horas_1 ="09:00 a 14:59"

Horas_2 ="15:00 a 18:59"

Horas_3 ="19:00 a 04:00"

Valor_1 = 1200;

Valor_2 = 1400;

Valor_3 = 1600;

try{

Fecha_1_1 = sdf.parse(Horas_1.substring(0,5) +":00");

Hr_1_1.setTime(Fecha_1_1.getTime());

Fecha_1_2 = sdf.parse(Horas_1.substring(8,13) +":59");

Hr_1_2.setTime(Fecha_1_2.getTime());

Fecha_2_1 = sdf.parse(Horas_2.substring(0,5) +":00");

Hr_2_1.setTime(Fecha_2_1.getTime());

Fecha_2_2 = sdf.parse(Horas_2.substring(8,13) +":59");

Hr_2_2.setTime(Fecha_2_2.getTime());

Fecha_3_1 = sdf.parse(Horas_3.substring(0,5) +":00");

Hr_3_1.setTime(Fecha_3_1.getTime());

Fecha_3_2 = sdf.parse(Horas_3.substring(8,13) +":00");

Hr_3_2.setTime(Fecha_3_2.getTime());

}catch(ParseException pe){}

Valor_Total = 0;

long Aux = 0, Aux2 = 0;

if (Hr_Ini.getTime() >= Hr_1_1.getTime() && Hr_Ini.getTime() <= Hr_1_2.getTime()){

if (Hr_Fin.getTime() >= Hr_1_1.getTime() && Hr_Fin.getTime() <= Hr_1_2.getTime()){

Valor_Total = (long)Math.ceil((double)Minutos * Math.ceil((double)Valor_1 / 60));

}

elseif (Hr_Fin.getTime() >= Hr_2_1.getTime() && Hr_Fin.getTime() <= Hr_2_2.getTime()){

Aux = Hr_Fin.getTime() - Hr_2_1.getTime();

Aux = Aux / 1000;

Aux = Aux / 60;

Valor_Total = (long)Math.ceil((double)(Minutos - Aux) * Math.ceil((double)Valor_1 / 60));

Valor_Total = (long)Math.ceil((double)Valor_Total + ((double)Aux * Math.ceil((double)Valor_2 / 60)));

}

elseif (Hr_Fin.getTime() >= Hr_3_1.getTime() && Hr_Fin.getTime() <= Hr_3_2.getTime()){

Aux2 = Hr_2_2.getTime() - Hr_2_1.getTime();

Aux2 = Aux2 / 1000;

Aux2 = Aux2 / 60;

Valor_Total = (long)Math.ceil((double)Aux2 * Math.ceil((double)Valor_2 / 60));

Aux = Hr_Fin.getTime() - Hr_3_1.getTime();

Aux = Aux / 1000;

Aux = Aux / 60;

Valor_Total = (long)Math.ceil(((double)Minutos - (double)Aux - (double)Aux2) * Math.ceil((double)Valor_1 / 60));

Valor_Total = (long)Math.ceil((double)Valor_Total + Math.ceil((double)Aux * Math.ceil((double)Valor_3 / 60)));

}

}

elseif (Hr_Ini.getTime() >= Hr_2_1.getTime() && Hr_Ini.getTime() <= Hr_2_2.getTime()){

if (Hr_Fin.getTime() >= Hr_2_1.getTime() && Hr_Fin.getTime() <= Hr_2_2.getTime()){

Valor_Total = (long)Math.ceil((double)Minutos * Math.ceil((double)((double)Valor_2 / 60)));

}

elseif (Hr_Fin.getTime() >= Hr_3_1.getTime() && Hr_Fin.getTime() <= Hr_3_2.getTime()){

Aux = Hr_Fin.getTime() - Hr_3_1.getTime();

Aux = Aux / 1000;

Aux = Aux / 60;

Valor_Total = (Minutos - Aux) * (Valor_2 / 60);

Valor_Total = Valor_Total + (Aux * (Valor_3 / 60));

}

}

elseif (Hr_Ini.getTime() >= Hr_3_1.getTime() && Hr_Ini.getTime() <= Hr_3_2.getTime()){

Valor_Total = (long)Math.ceil((double)Minutos * Math.ceil((double)((double)Valor_3 / 60)));

}

return Valor_Total;

}

Please help me...

Regards...

Mensaje editado por:

MetalTux

[7332 byte] By [MetalTuxa] at [2007-11-26 18:38:19]
# 1
Why is this in Swing forum?
kirillga at 2007-7-9 6:12:23 > top of Java-index,Desktop,Core GUI APIs...
# 2
Sorry... but I don't know where put it...Please sorry me.... and tell me where I have to put this on....Regards...
MetalTuxa at 2007-7-9 6:12:23 > top of Java-index,Desktop,Core GUI APIs...
# 3
http://forum.java.sun.com/forum.jspa?forumID=54
kirillga at 2007-7-9 6:12:23 > top of Java-index,Desktop,Core GUI APIs...