Name: jl125535 Date: 01/27/2003
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
A DESCRIPTION OF THE PROBLEM :
java.sql.Time#toString() was apparently forgotten when
java.sql.Date#toString() was enhanced. This suggested
enhancement catches java.sql.Time toString() up and also
incorporates improvements beyond current java.sql.Date
toString() technology to reduce brittleness and enhance
performance (see bug 4808825).
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
Current code:
public String toString () {
int hour = super.getHours();
int minute = super.getMinutes();
int second = super.getSeconds();
String hourString;
String minuteString;
String secondString;
if (hour < 10) {
hourString = "0" + hour;
} else {
hourString = Integer.toString(hour);
}
if (minute < 10) {
minuteString = "0" + minute;
} else {
minuteString = Integer.toString(minute);
}
if (second < 10) {
secondString = "0" + second;
} else {
secondString = Integer.toString(second);
}
return (hourString + ":" + minuteString + ":" + secondString);
}
Suggested enhancement:
public String toString () {
int hour = super.getHours();
int minute = super.getMinutes();
int second = super.getSeconds();
char buf[] = {
Character.forDigit((hour/10)%10,10),
Character.forDigit(hour%10,10),
':',
Character.forDigit(minute/10,10),
Character.forDigit(minute%10,10),
':',
Character.forDigit(second/10,10),
Character.forDigit(second%10,10)};
return new String(buf);
}
---------- END SOURCE ----------
(Review ID: 153578)
======================================================================
- duplicates
-
JDK-8058230 Improve java.sql toString formatting
-
- Resolved
-