0

I'm reading a record of data from a cassandra table. Creating a Java object that I built. Setting all the values with what I get from the record of data (I'm getting these values from the record using Jackson). When I look at the json request I'm seeing a long doulbe like value. Wondering what format that is in? And then why it's negative? Here's what I got...

JsonNode ccEventNode = new ObjectMapper().readTree(row.getString(0));
ccEventNode.get("last_pyflt_dt")

This gives me a value of "1901-01-01". I then...

CCEvent ccEvent = new CCEvent;
ccEvent.getHistory().setLast_pyflt_dt(new SimpleDateFormat("yyyy-MM-dd").parse(ccEventNode.get("last_pyflt_dt").textValue()));

This gives me a value for the Date field I just set of "Tue Jan 01 00:00:00 EST 1901"

But when I read the JSON request once I'm done setting all the other values I am seeing the value as...

"lastPaymentFloatDate":-2177434800000

My first question is. What is that value? Is it number of minutes from a certain date? Why is it negative? It's causing issues when I send it to the webservice. When I have other dates that are like "2020-02-04" it doesn't cause any issues. It also shows me in the request a large number like the one above but it's not negative. A bit confused.

  • Date can be represented on many ways. What `type` do you use to store it in `CCEevnt` class? What type is used to store it in `Cassandra` table? Take a look on that question: [Spring Boot Jackson date and timestamp Format](https://stackoverflow.com/questions/55256567/spring-boot-jackson-date-and-timestamp-format) – Michał Ziober Mar 06 '20 at 21:05

2 Answers2

3

-2177434800000 is the number of milliseconds before the epoch time.
Epoch time is 1 January 1970 00:00:00 which is considered 0 milliseconds. Any time before it is negative and after it is positive. Think of epoch time as 0 in the number line.
You can read more about it here and here.

Also ,you can verify that -2177434800000 stands for 1901-01-01 on this epoch convertor website.

Neeraj
  • 2,376
  • 2
  • 24
  • 41
  • Thank you!! Now how would i convert that back. it seems my webservice needs that value as epoch and then is returning it that way. But When i write back into cassandra, cassandra does NOT like that at all – Brian Gurka Mar 10 '20 at 14:11
0
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
Procrastinator
  • 2,526
  • 30
  • 27
  • 36
  • Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – Mark Rotteveel Mar 03 '23 at 10:59