The calculation rules are below, just need to pass in the creation of the timestamp can return the desired content, not explained ha, everyone to see the code, not complex:
/// Evaluate the time rule, the 11-bit timestamp is passed in
String getCommentTime(int createAt) {
// get the timestamp of the current time ~ / is a double, with a decimal point
var cTimestamp = DateTime.now().millisecondsSinceEpoch;
var allStamp = cTimestamp - createAt;
int day = (cTimestamp - createAt) ~/ (1000 * 60 * 60 * 24);
int hour = (cTimestamp - createAt) % (1000 * 60 * 60 * 24) ~ / (1000 * 60 * 60);
int minute = (cTimestamp - createAt) % (1000 * 60 * 60 * 24) % (1000 * 60 * 60) ~ / (1000 * 60);
int second = (cTimestamp - createAt) % (1000 * 60 * 60 * 24) % (1000 * 60 * 60) % (1000 * 60) ~ /1000;
if (day == 0 && hour == 0 && minute == 0 && second < 60) {
return 'just';
} else if (day == 0 && hour == 0 && minute < 60) {
// You can also use toString ()
return '${minute.tostring ()} minutes ago ';
} else if (day == 0 && hour < 24 && hour > 0) {
return '${hour.toString()} hour ago ';
} else if (day > 0 && day < 7) {
return '${day. The toString ()} days ago';
} else {
DateTime date = DateTime.fromMillisecondsSinceEpoch(createAt);
return date.toLocal().toString().substring(0.19); }}Copy the code
Feel useful, give 👍!