How do you put the date in the right format at the last downloaded file?
-
At the end of the code, I return to the column of the table the date of the last entered file, but the format of the date is "The Aug 26 16:45:55 SAMT 2021." I want to make another conclusion to "dd.mm.yyyy," how is that possible? Here's the code:
@Override public Component generateCell(T entity) { String dataLastAttachment = ""; List<CardAttachment> attachments = entity.getAttachments();
if (CollectionUtils.isNotEmpty(attachments)) { CardAttachment attachment = attachments.get(attachments.size() - 1); dataLastAttachment = attachment.getCreateTs().toString(); } return new Table.PlainTextCell(dataLastAttachment);
-
The date/times that return from the method
createTs
using the appropriate format.This can be done either
SimpleDateFormat
ifcreateTs
returning a copy of the classjava.util.Date
:import java.text.*;
// ...
@Override
public Component generateCell(T entity) {
String dataLastAttachment = "";
List<CardAttachment> attachments = entity.getAttachments();if (CollectionUtils.isNotEmpty(attachments)) { CardAttachment attachment = attachments.get(attachments.size() - 1); DateFormat sdf = new SimpleDateFormat("dd.MM.yyyy"); dataLastAttachment = sdf.format(attachment.getCreateTs()); } return new Table.PlainTextCell(dataLastAttachment);
}
If method
createTs()
returning the copyInstant
/ZonedDateTime
/LocalDateTime
from Java Date/Time API, formatting should be usedDateTimeFormatter
with similar patternum (in the case ofInstant
You've got to have a clock belt.import java.time.;
import java.time.format.;// ...
if (CollectionUtils.isNotEmpty(attachments)) { // предполагается что список отсортирован по дате CardAttachment attachment = attachments.get(attachments.size() - 1); DateTimeFormatter formatter = DateTimeFormatter .ofPattern("dd.MM.uuuu") .withZone(ZoneId.systemDefault()); dataLastAttachment = formatter.format(attachment.getCreateTs()); }