How do I fix an error? When I send a message, the date appears correctly, but when I receive a message, the date appears incorrectly. For example, 5 p.m., the date appears at 8 p.m. Here is a three-hour difference.
AdapterChat:
Calendar cal = Calendar.getInstance(Locale.US);
cal.setTimeInMillis(Long.parseLong(timeStamp));
String dateTime = DateFormat.format("dd/MM/yyyy hh:mm aa", cal).toString();
ChatActivity:
String timestamp = String.valueOf(System.currentTimeMillis());
I tried changing Locale.US to Locale.getDefault, but the error was not fixed.
AdapterChat:
Calendar cal = Calendar.getInstance(Locale.getDefault());
cal.setTimeInMillis(Long.parseLong(timeStamp));
String dateTime = DateFormat.format("dd/MM/yyyy hh:mm aa", cal).toString();
ChatActivity:
String timestamp = String.valueOf(System.currentTimeMillis());
Don't use Calendar. Use classes from the java.time package.
As was stated, the sender/recipients can format a time stamp themselves in what ever form that meets their requirements. The following adjusts the time zone between East and West for a given Instant in time using your specified format.
prints