开发者

Why java.sql.Time.toString() adds hours?

Follow the simple a example

java.sql.Time t = new Time(1000);
System.out.println("Time t开发者_运维百科 =" + t);

This gives the following output:

Time t = 01:00:01

While I would expect:

Time t = 00:00:01

Could someone tell me how to get rid of the hours portion?


I think you should consider your current TimeZone and check the API of the constructor

http://download.oracle.com/javase/7/docs/api/java/sql/Time.html#Time(long)

I expect you are living somewhere in Europe ;-)


The Time object is normalized, i.e. the timezone of your JVM is taken into account.

Btw, instead of toString() you might want to use DateFormat#format(Date) and set the time zone on the DateFormat instance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜