我有一些代码运行一个进程,并从stdout和stderr异步读取,然后在进程完成时进行处理.它看起来像这样:
Process process = builder.start();
Thread outThread = new Thread(() -> {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
// Read stream here
} catch (Exception e) {
}
});
Thread errThread = new Thread(() -> {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()))) {
// Read stream here
} catch (Exception e) {
}
});
outThread.start();
errThread.start();
new Thread(() -> {
int exitCode = -1;
try {
exitCode = process.waitFor();
outThread.join();
errThread.join();
} catch (Exception e) {
} …
Run Code Online (Sandbox Code Playgroud) 我使用Hibernate(4.2)作为我的持久性提供程序,我有一个包含Date字段的JPA实体:
@Entity
@Table(name = "MY_TABLE")
public class MyTable implements Serializable {
. . .
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "START_DATE")
private Date startDate;
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
. . .
}
Run Code Online (Sandbox Code Playgroud)
与START_DATE对应的列定义为START_DATE TIMESTAMP
(无时区).
我在我的应用程序内部使用Joda-Time(2.3)来处理日期(总是在UTC中),并且在持久化实体之前,我使用toDate()
Joda的DateTime
类的方法来获取JDK Date
对象以遵守映射:
public void myMethod(DateTime startDateUTC) {
. . .
MyTable table = /* obtain somehow */
table.setStartDate(startDateUTC.toDate());
. . .
}
Run Code Online (Sandbox Code Playgroud)
当我在DB中查看存储的值时,我注意到某处(JDK?Hibernate?)使用代码运行的JVM的默认时区转换Date值.在我的情况下是"美国/芝加哥".
问题确实在夏令时(DST)附近显现出来.例如,如果内部时间是
2014-03-09T02:55:00Z
Run Code Online (Sandbox Code Playgroud)
它被存储为
09-Mar-14 03:55:00
Run Code Online (Sandbox Code Playgroud)
我想要的是将它存储为
09-Mar-14 …
Run Code Online (Sandbox Code Playgroud)