1
I am finalizing a Time Sheet project for accounting and it is my first project so I have not yet experienced manipulating date and time in java and database, without further delay:
I need to solely and exclusively make the following account through the system:
Time Check-in Time Check-out Lunch Check-out Lunch Check-out
08:00 11:00 13:00 17:00
Totaling 3 hours worked in the morning and 4 hours worked in the afternoon. I would like to know the best way to manipulate and make this account, I thought about turning into long but I could not complete the ideas. I know that by far this is a Minimal, Complete and Verifiable example, the more I like to understand how to do it and then turn around.
After watching several video lessons, I did it the way below, so I can figure out the duration between the hours of input and output, but I really thought it was a scam, who can help me improve this code, turn 23:00 into two integer attributes one of 23 and the other with value 00 does not seem right for me, I thank you already!
public void teste(){
int teste1 = (Integer.parseInt(jTextFieldHora1.getText().substring(0,2)));
int teste2 = (Integer.parseInt(jTextFieldHora1.getText().substring(3,4)));
int teste3 = (Integer.parseInt(jTextFieldHora2.getText().substring(0,2)));
int teste4 = (Integer.parseInt(jTextFieldHora2.getText().substring(3,4)));
LocalTime time1 = LocalTime.of(teste1,teste2);
LocalTime time2 = LocalTime.of(teste3,teste4);
System.out.println(ChronoUnit.MINUTES.between(time1, time2));
}
Or simply upgrade to java-8, which already has these native classes.
– user28595
Zulian I did the way you showed me and is giving error in that word Hours said it does not exist, I edited my question and I found a way to do just did not become cool, if you can help me thank.
– Dhouglas Silva Gomes
I updated my reply @Dhouglassilvagomes, check it out!
– Zulian