在 Oracle 数据库中插入时间戳后缺少日光调整



我正在使用带有休眠的 Spring boot 将以下类的对象写入 oracle db jpa

@Entity
@Table(name="signins")
public class UserSignIn
{
@Id
@GenericGenerator(name="signinIdGen" , strategy="increment")
@GeneratedValue(generator="signinIdGen")
@Column(name="signin_id",nullable=false)
private long id;
@Column(name="timestamp", columnDefinition="timestamp default current_timestamp", nullable = false)
@Temporal(TemporalType.TIMESTAMP)
private Date timestamp;
@Column(name="username", columnDefinition="varchar(50)", nullable=false)
private String username; 
}

我使用从 spring boot jpa 扩展CrudRepository的接口保存和检索对象:

public interface SigninDao extends CrudRepository<UserSignIn, Long> {
}

插入我为其设置的示例UserSigninsignin.setTimestamp(somelong)我在数据库中看到该条目的时间戳为
2018-08-10 15:59:48.667000

问题:当我检索同一条目时,时间戳是 -1 小时
"timestamp":"2018-08-10T14:59:48.667+0000"。插入时,Date时间戳似乎将夏光调整设置为 0。

感谢您的帮助

您插入的时间戳是 2018-08-10 15:59+0100。检索的时间戳为 2018-08-10 14:59+0000。这是完全相同的时间,只是具有两种不同的时区格式。如果您需要不同的格式或不同的输出,您只需在格式化程序中为日期配置正确的时区(如果需要详细的帮助,请在其中发布一些代码来检索时间戳以及如何配置 JSON 格式化程序(。

存储时间戳时,它会自动从本地时间转换并存储为 UTC 时间戳,这也是检索到的内容。因此,存储的时间戳不需要记住它是否有 DST,因为转换发生在存储它之前。

最新更新