Advertisement
Guest User

calcular

a guest
Oct 16th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. public void calcular(View view) {
  2.         if(d.getId()>0){
  3.             SimpleDateFormat formato = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
  4.             Date inicio = new Date();
  5.             try{
  6.                 inicio = formato.parse(d.getEntrada());
  7.  
  8.             }catch(Exception ex){
  9.                 ex.printStackTrace();
  10.             }
  11.  
  12.              Date fin = new Date();
  13.              try{
  14.                 fin = formato.parse(d.getSalida());
  15.              }catch(Exception ex){
  16.                  ex.printStackTrace();
  17.                  fin = new Date();
  18.                  d.setSalida(formato.format(fin));
  19.             }
  20.  
  21.             long diff = fin.getTime() - inicio.getTime();
  22.             int tiempo = (int) (diff/1000/60);
  23.             int horas = 0;
  24.             try{
  25.                 horas = Integer.parseInt(montoPorHora.getText().toString().trim());
  26.             }catch(NumberFormatException ex){
  27.                 ex.printStackTrace();
  28.             }
  29.             //int tiempo = (int)(TimeUnit.HOURS.convert(diff, TimeUnit.MILLISECONDS));
  30.             int total = tiempo * horas;
  31.             d.setTotal(total);
  32.             //Toast.makeText(view.getContext(), "Total: $"+total, Toast.LENGTH_SHORT).show();
  33.             labelTotal.setText("Total para id "+d.getId()+" $"+d.getTotal());
  34.         }else{
  35.             Toast.makeText(this, "LUL", Toast.LENGTH_SHORT).show();
  36.         }
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement