I am trying to create a timestamp in the format "mm/dd/yyyy hh:mm a". My app was originally crashing but I tried a different method and it doesn't crash anymore but on the chat screen it shows "java.text.SimpleDateFormat@4f47c0fb" instead of the timestamp.
Here is a screen shot of the chat screen timestamp
This is from my AdapterChat.java file
@Override
public void onBindViewHolder(@NonNull MyHolder myHolder, int i) {
//Get data
String message = chatList.get(i).getMessage();
String timeStamp = chatList.get(i).getTimestamp();
//Convert time stamp to mm/dd/yyyy hh:mm am/pm
//Calendar cal = Calendar.getInstance(Locale.ENGLISH);
//cal.setTimeInMillis(Long.parseLong(timeStamp));
String dateTime = new SimpleDateFormat("MM/dd/yyyy hh:mm a", Locale.getDefault()).toString();
//Set data
myHolder.messageTv.setText(message);
myHolder.timeTv.setText(dateTime);
try {
Picasso.get().load(imageUrl).into(myHolder.profileIv);
} catch (Exception e) {
}
//Set seen/delivered status of message
if (i == chatList.size() - 1) {
if (chatList.get(i).isSeen()) {
myHolder.isSeenTv.setText("Seen");
}
else {
myHolder.isSeenTv.setText("Delivered");
}
}
else {
myHolder.isSeenTv.setVisibility(View.GONE);
}
}
I commented out the 2 lines of code that were causing it to crash and I tried the new method under it. Can someone guide me in the right direction. I'm not sure what I'm doing wrong. Any help would be appreciated. Thanks!