在数据库中保存日期时,我遇到了一个非常奇怪的行为.在我的(Linux centOS 6.2)服务器上,我使用glassfish应用服务器(3.1.1-build 12)和Java(1.7.0_09),应用程序是用Java+GWT开发的,它使用PostgreSQL server(9.2.1).在应用程序中,有几个日期字段保存在数据库中.日期字段使用日期 Select 器(http://code.google.com/p/gwt-datepicker,r30).
db关系的日期属性是日期类型(不是时间戳).有些日期会提前一天保存在数据库中.这个问题只发生在时间间隔之间,例如1968年3月31日至1968年10月27日之间,这让我想到了某种夏季时间问题.但是,由于1969年没有发生这种情况,例如,我不能很好地孤立这个问题.我想找一个问题发生的时间间隔.For example, if I select 19.05.1968 in the application, after saving in the database the date is saved as 18.05.1968.
奇怪的是,我在另一台服务器上有同一个应用程序的另一个istance,并且它们在相同的日期被正确保存.
- 玻璃鱼形态;
- java(java.util.Date实现?);
- 我缺少某种服务器配置
我试图将服务器的所有配置都设置为Europe/Rome(我的时区),但什么也没有.知道吗?我如何解决或调查这个问题?
UPDATE:
创建项目日期的代码部分是:
Date d = dateField.getSelectedDate();
if (d != null) {
txtVal = DateTimeFormat.getFormat("dd/MM/yyyy").format(d);
}
其中dateField声明为:
transient private DatePicker dateField;
包是org.zenika.widget.client.datePicker.DatePicker
(前面提到的gwt-datepicker-r30),DateTimeFormat指的是com.google.gwt.i18n.shared.DateTimeFormat
UPDATE after accepting the answer:
我使用了以下解决方法:创建日期时,我使用以下代码:
final long hours12 = 12L * 60L * 60L * 1000L;
Date d = new Date(d1.getTime() + hours12);