Spring返回有关日期

时间:2016-03-14 16:17:34

标签: spring-mvc spring-boot spring-data-mongodb

我是春天网络应用程序的新手。在应用程序中有一个API应该返回我之前使用另一个api保存的日期。该日期在iOS上消耗。它一切正常,但作为日期的一部分返回的数据量是巨大的,我想知道是否可以关闭它。以下是数据样本:

"availability": {
"offset": {
"totalSeconds": -25200
"id": "-07:00"
"rules": {
"fixedOffset": true
"transitions": [0]
"transitionRules": [0]
}-
}-
"zone": {
"id": "America/Los_Angeles"
"rules": {
"fixedOffset": false
"transitions": [127]
0:  {
"offsetBefore": {
"totalSeconds": -28378
"id": "-07:52:58"
"rules": {
"fixedOffset": true
"transitions": [0]
"transitionRules": [0]
}-
}-
"offsetAfter": {
"totalSeconds": -28800
"id": "-08:00"
"rules": {
"fixedOffset": true
"transitions": [0]
"transitionRules": [0]
}-
}-
"duration": {
"seconds": -422
"negative": true
"zero": false
"units": [2]
0:  "SECONDS"
1:  "NANOS"
-
"nano": 0
}-
"gap": false
"overlap": true
"dateTimeAfter": {
"year": 1883
"month": "NOVEMBER"
"dayOfMonth": 18
"dayOfWeek": "SUNDAY"
"dayOfYear": 322
"monthValue": 11
"hour": 12
"minute": 0
"second": 0
"nano": 0
"chronology": {
"id": "ISO"
"calendarType": "iso8601"
}-
}-
"dateTimeBefore": {
"year": 1883
"month": "NOVEMBER"
"dayOfMonth": 18
"dayOfWeek": "SUNDAY"
"dayOfYear": 322
"monthValue": 11
"hour": 12
"minute": 7
"second": 2
"nano": 0
"chronology": {
"id": "ISO"
"calendarType": "iso8601"
}-
}-
"instant": {
"nano": 0
"epochSecond": -2717640000
}-
}-
1:  {
"offsetBefore": {
"totalSeconds": -28800
"id": "-08:00"
"rules": {
"fixedOffset": true
"transitions": [0]
"transitionRules": [0]
}-
}-

我不想要所有这些数据,因为我的查询需要很长时间才能返回。我做错了什么或错过了一些告诉我要回归的旗帜。日期最初存储为ZonedDateTime,还是以其他格式存储日期?

1 个答案:

答案 0 :(得分:3)

您没有显示正在序列化的POJO。所以我打赌你正在使用像Joda Time或Java8的LocalDateTime这样的Date抽象。您可能希望将此POJO更改为仅包含简单的Long时间戳或仅Date,这应该序列化为1970年代以来的毫秒数。

对于上述转换,请看一下这些SO答案:

Converting between java.time.LocalDateTime and java.util.Date

How to get milliseconds from LocalDateTime in Java 8