Iso*_*Iso 7 java spring jdbc spring-data-jpa spring-boot
我没有为我的JPA应用程序设置CET时区,该应用程序使用AuditingEntityListener来增加创建/最后修改的日期。
我已经尝试过的事情:
在我的application.properties(两种组合)中:
spring.jpa.properties.hibernate.jdbc.time_zone=UTC+1
spring.jpa.properties.hibernate.jdbc.time_zone=CET
Run Code Online (Sandbox Code Playgroud)
为我的JDBC连接添加了时区(两种组合)
spring.datasource.url=jdbc:mysql://host:3306/db?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC+1
spring.datasource.url=jdbc:mysql://host:3306/db?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=CET
Run Code Online (Sandbox Code Playgroud)
添加了后构建(应用程序级别)
@PostConstruct
void started() {
TimeZone.setDefault(TimeZone.getTimeZone("UTC+1"));
}
Run Code Online (Sandbox Code Playgroud)
还尝试使用以下方法在数据库级别设置时区:
SET time_zone='+01:00';
Run Code Online (Sandbox Code Playgroud)
无论如何都没有成功,我是否缺少某些东西?
使用@createdDate如下:
编辑
@Data
@Builder
@Entity
@EntityListeners(AuditingEntityListener.class)
@NoArgsConstructor
@AllArgsConstructor
public class OrderHistoryRecord {
@Id
@GeneratedValue
@JsonIgnore
private Long id;
@NotNull
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Order.class)
@JoinColumn(name = "order_id", updatable = false)
@JsonIgnore
private Order order;
@CreatedDate
private Date date;
@Enumerated(EnumType.STRING)
private PaymentStatus paymentStatus;
@Enumerated(EnumType.STRING)
private ShipmentStatus shipmentStatus;
@Enumerated(EnumType.STRING)
private OrderHistoryRecordType type;
}
Run Code Online (Sandbox Code Playgroud)
尝试“ECT”吗?
Map<String, String> map = new HashMap<>(64);
map.put("ACT", "Australia/Darwin");
map.put("AET", "Australia/Sydney");
map.put("AGT", "America/Argentina/Buenos_Aires");
map.put("ART", "Africa/Cairo");
map.put("AST", "America/Anchorage");
map.put("BET", "America/Sao_Paulo");
map.put("BST", "Asia/Dhaka");
map.put("CAT", "Africa/Harare");
map.put("CNT", "America/St_Johns");
map.put("CST", "America/Chicago");
map.put("CTT", "Asia/Shanghai");
map.put("EAT", "Africa/Addis_Ababa");
map.put("ECT", "Europe/Paris");
map.put("IET", "America/Indiana/Indianapolis");
map.put("IST", "Asia/Kolkata");
map.put("JST", "Asia/Tokyo");
map.put("MIT", "Pacific/Apia");
map.put("NET", "Asia/Yerevan");
map.put("NST", "Pacific/Auckland");
map.put("PLT", "Asia/Karachi");
map.put("PNT", "America/Phoenix");
map.put("PRT", "America/Puerto_Rico");
map.put("PST", "America/Los_Angeles");
map.put("SST", "Pacific/Guadalcanal");
map.put("VST", "Asia/Ho_Chi_Minh");
map.put("EST", "-05:00");
map.put("MST", "-07:00");
map.put("HST", "-10:00");
SHORT_IDS = Collections.unmodifiableMap(map);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
814 次 |
最近记录: |