![](/img/trans.png)
[英]converting GMT format String to Datetime in spring boot Java
[英]Converting MongoDB DateTime to IST format when saving in the DB using java Spring Boot
我有一個春季啟動應用程序,我正在使用MongoDB作為數據庫。我想以IST格式在MongoDB中保存日期和時間。
我已經在模型類中使用了這些注釋,但這是行不通的。
ZoneId zoneId = ZoneId.of("America/Chicago");
@JsonFormat(pattern="dd-MM-yyyy HH:mm:ss",timezone = "IST")
@Temporal(TemporalType.TIMESTAMP)
@CreatedDate
private LocalDateTime createdDate = LocalDateTime.now(zoneId);
這是將其保存在MonogoDB羅盤社區中后的顯示方式。我想在保存后也顯示與MongoDB中的Postman相同的格式。
您需要使用@EnableMongoAuditing
( 在此處參考 )。
設置dateTimeProviderRef = "istDateTimeProvider"
@Bean
public DateTimeProvider istDateTimeProvider() {
return () -> new GregorianCalendar(TimeZone.getTimeZone("IST"));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.