# JsonFormat ```java= @ApiModelProperty( name = "id", value = "id") @JsonFormat(shape = JsonFormat.Shape.STRING) protected Long id; ``` ```java= @Excel(name = "读取时间") @ApiModelProperty(name="readTime", value = "读取时间") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") private String readTime; ``` #### java時間和db時間比對時,相差8小時 情境:想找到 create_time >= createTimeStart && create_time <= createTimeEnd 區間的資料。 原設定:createTimeStart 2022-02-11 19:00:00 ; createTimeEnd 2022-02-12 19:00:00. 但是當 create_time 為 2022-02-12 18:00:00,卻找不到資料,start and end time傳參必須 -8hr 才能對應對的資料。 解法:傳入unix timestamp 毫秒等級(ex:1642844956000) ```java= @JsonFormat(shape = JsonFormat.Shape.NUMBER) private Date createTimeStart; @JsonFormat(shape = JsonFormat.Shape.NUMBER) private Date createTimeEnd; ``` ###### tags: `time` `date` `datetime`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up