0

i have a string like this on my java code:

17:00

I want to make a subtraction using a constant integer

 public static final int MAX_DUREE_TRAVAIL_JOUR = 10; 

When i do this:

Integer.parseInt("17:00") - ConstantesIntervention.MAX_DUREE_TRAVAIL_JOUR

I have this error:

java.lang.NumberFormatException: For input string: "17:00"

Thx.

Mercer
  • 9,736
  • 30
  • 105
  • 170

4 Answers4

2

What are you expecting to happen? 17:00 is not a valid string representation of an integer.

You probably want to use a SimpleDateFormat to parse the string as a Date and do the time arithmetic on that.

Alternatively, take a look at the JodaTime library which provides much better handling of dates/times.

SimonC
  • 6,590
  • 1
  • 23
  • 40
1

17:00 cant be to converted to an integer.

4J41
  • 5,005
  • 1
  • 29
  • 41
0

The answer by Ajai is correct.

Some advice: When working with dates and times, work with dates and times (not strings and integers). Meaning use date-time classes.

Use a good date-time library (not the mess that is java.util.Date/Calendar).


P.S. Mercer, Joda-Time even knows how to speak français. See another answer of mine today for an example.

Community
  • 1
  • 1
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
0

Because 17:00 is not a Correct integer.You should divide the string and use Integer.parse() then according to your business logic use those integers.

PrasadGeek
  • 21
  • 4