繁体   English   中英

如何使用springboot在json对象中表示日历日期

[英]How to represent a Calendar date in a json object using springboot

我有以下json对象:

{
"username":"test",
"customerName":"test",
"accessReasons":"tes",
"leaseHours":"8"
}

这表示某个用户必须执行某项任务的时间(即sysdate + leaseHours)

在我的控制器上,我创建了一个对象,其中包含我在json中收到的信息:

thatObject obj=new thatObject (jsonObjectFromPostBody)

通过这样做,以这种方式创建了该对象的实例:

public thatObject(thatObject aci) {
    this.username=aci.getUsername();
    this.customerName=aci.getCustomerName();
    this.accessReasons=aci.getAccessReasons();
    this.beginDate= new GregorianCalendar();
    long sum=beginDate.getTimeInMillis()+aci.getLeaseHours().getTimeInMillis();
    this.endDate=(Calendar)beginDate.clone();
    this.endDate.setTimeInMillis(sum);
}

如您所见,我的endDate是初始日期+用户有权激活的时间(在这种情况下是8小时)

但我的问题是我正在使用日历而且我无法在我的json对象上代表那些8小时,所以当我计算endTime时它将为0,我如何在我的json上代表那些8小时或者将这8小时加到我的beginDate上变量?

你为什么不只是改变leaseHours属性的类型为IntegerthatObject? 在这种情况下,您可以执行以下操作:

long sum=beginDate.getTimeInMillis() + aci * 60 * 60 * 1000;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM