I would like to either display the date if a message was not sent today, or the time if the message was sent today.
I use the Firebase server on which I save the server TimeStamp for every message I send.
This is an excerpt from my code:
Text(
snapshot.data.documents[0]["time"] == DateTime.now()
? DateFormat.Hm().format(snapshot.data.documents[0]["time"].toDate()).toString()
: DateFormat.yMd().format(snapshot.data.documents[0]["time"].toDate()).toString(),
style: TextStyle(
color: Colors.grey,
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
)
Unfortunately, my code only gives me the date. In addition, the date is output as follows: 3/27/2021. However, I want the date to be displayed as follows: 03/27/2021.