postman 传递日期,POSTMAN返回具有更改值的日期字段

I am consuming a REST service and I am receiving a JSON with date attributes that do not match what is in my database. I have two fields called "initialDate" and "finalDate". In the database they are like this:

07/MAR/19 00:00:00

07/SEP/19 23:59:59

The database timezone:

select dbtimezone from dual;

+00:00

In my object, inside the Java class, the content of the attributes comes as:

public class Klass {

@NotNull

private Date initialDate; //initialDate.toString() "Thu Mar 07 00:00:00 CLT 2019"

@NotNull

private Date finalDate; // finalDate.toString() "Sat Sep 07 23:59:59:9 CLT 2019"

public Date initialDate() {

return this.initialDate == null ? null : new Date(initialDate.getTime());

}

public void setInitialDate() {

this.initialDate = initialDate == null ? null : new Date(initialDate.getTime());

}

public Date finalDate() {

return this.finalDate == null ? null : new Date(finalDate.getTime());

}

public void setFinalDate() {

this.finalDate = finalDate == null ? null : new Date(finalDate.getTime());

}

}

However, in my POSTMAN, it returns this:

initialDate: "2019-03-07T03:00:00Z",

finalDate: "2019-09-08T02:59:59Z"

Why is POSTMAN adding these 3 hours to my service response? I already try to change the timezone of Windows, but there's no difference.

解决方案

After some research, I've found this article that send me to a solution.

According by the write-up, In my custom class, I set the following attributes:

DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSZ");

df.setTimeZone(TimeZone.getDefault());

this.setDateFormat(df)

In this ways, I get the result as I'd like:

{

"initialDate" : "2019-03-07T00:00:00.000-0300",

"finalDate" : "2019-09-07T23:59:59.000-0300"

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值