开发者

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

开发者 https://www.devze.com 2023-03-20 19:40 出处:网络
Follow the simple a example java.sql.Time t = new Time(1000); System.out.println(\"Time t开发者_运维百科 =\" + t);

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

精彩评论

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