POSTMAN返回具有更改值的日期字段 [英] POSTMAN is returning date fields with changed values
问题描述
我正在使用REST服务,并且收到的JSON具有与数据库中的内容不匹配的日期属性.我有两个名为"initialDate"的字段,和"finalDate".在数据库中,它们是这样的:
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
数据库时区:
select dbtimezone from dual;
+00:00
在我的对象的Java类内部,属性的内容如下:
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());
}
}
但是,在我的POSTMAN中,它返回以下内容:
However, in my POSTMAN, it returns this:
initialDate: "2019-03-07T03:00:00Z",
finalDate: "2019-09-08T02:59:59Z"
为什么POSTMAN将这3个小时添加到我的服务响应中?我已经尝试更改Windows的时区,但是没有区别.
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"
}
这篇关于POSTMAN返回具有更改值的日期字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!