简体   繁体   English

Java.sql.time的替代品

[英]Alternative to Java.sql.time

Is java.sql.time not working properly? java.sql.time无法正常工作吗?

This is my code 这是我的代码

         Time lowertime=new Time(date.getTime());
         lowertime.setHours(lowertime.getHours()-11);
         System.out.println(lowertime);
         Time uppertime=lowertime;
         uppertime.setHours(lowertime.getHours()+1);
         System.out.println(uppertime);
         System.out.println(lowertime);

Result Obtained 获得结果

02:11:13
03:11:13
03:11:13

The result should be: 结果应该是:

 02:11:13
 03:11:13
 02:11:13

I searched the java docs and its deprecated.Whats the alternative to get a time range of 1 hour or (say 58 minutes). 我搜索了java文档,并且不推荐使用它。可以选择获得1小时或(比如58分钟)的时间范围。

I am using java,Hibernate Framework and MySql database.Whats the best option for me. 我正在使用java,Hibernate Framework和MySql数据库。这对我来说是最好的选择。

Time uppertime=lowertime;

Due to the above line, uppertime and lowertime are two references to the same object. 由于上面的行,uppertime和lowertime是对同一对象的两个引用。 Each time you modify one, you also modify the other, since they are in fact a single, unique object. 每次修改一个,你也修改另一个,因为它们实际上是一个唯一的对象。 You need to create a copy: 您需要创建一个副本:

Time uppertime = new Time(lowertime.getTime());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM