Quiz duration is specified as days, hours and minutes each in integers.
I am trying to convert combination of these to seconds. Below code I tried. but it always returns 0 seconds. I am using jdk 6
Integer hours = 3, days=4, minutes=20;
javax.xml.datatype.Duration duration = DatatypeFactory.newInstance().newDuration(true, 0, 0,
days,
hours,
minutes,
0);
Integer seconds = duration.getSeconds(); // It always returns zero
Please guide.
The JavaDocs for
javax.xml.datatype.Duration.getSeconds()sayIf you want to calculate the total amount of seconds this duration is representing, you will have to calculate them yourself, maybe like this (there may be better solutions):
For certain durations, an
intwill not be sufficient, keep that in mind, please.Consider using
java.time.Durationinstead, if possible.There is a backport of
java.timefor Java 6 and 7, but unfortunately, not for below.