Skip to main content

I face a very weird situation when trying to convert the message.created_at to the timestamp.

 

Firstly, my understanding is that the date type for the created_at is float. Is that correct? So the number is the seconds passed since epic, and fraction is the millisconds. Did I understand it correctly?

 

Then I used the following code to turn it into Java Date object.

new java.util.Date(TimeUnit.SECONDS.toMillis((long)last_message.created_at.floatValue()))
Then I used the following code to transform the Date into string
new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
 
There are two things weird:
(1) I have two messages, sent in absolutely different time, 20 - 30 seconds apart. But somehow the output of timestamp is exactly the same.
(2) For afternoon 1pm, instead showing 13:xx:xx, it shows 01:xx:xx.

Hi Rob,

Yes - these are UNIX timestamps to a per-second granularity (or millisecond if you include the float part).

I’m not super-familiar with Java, however;

1) I have two messages, sent in absolutely different time, 20 - 30 seconds apart. But somehow the output of timestamp is exactly the same.

Unsure what’s happening here, but feels like something is off in the way you’re converting the timestamp. I’d recommend testing and printing the output after each conversion step to see where something might be going wrong. 

(2) For afternoon 1pm, instead showing 13:xx:xx, it shows 01:xx:xx.

`HH` vs `hh` will give you different formats; (See Java docs)

  • HH is Hour in day (0-23)
  • hh is hour in AM/PM (1-12)

 


Reply