I am creating a chat application and I want to print the date and time in chat bubble whenever the message is sent or received.
I used the below code to get and convert the date and time.
long itemLong = (long) (chatMessage.getTime()*1000);
Date itemDate = new Date(itemLong);
String itemDateStr = new SimpleDateFormat("dd-MMM HH:MM").format(itemLong);
holder.time.setText(itemDateStr);
The itemLong variable gets the value 1.4847986E15, which is converted to date and timestamp in the format I mentioned in SimpleDateFormat, but eveytime some random date and time gets displayed not at which the message was sent or received.
I tried various solutions but I am unable to get the correct date and time. Any help is appreciated.