Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save witchfindertr/b7c5596eaed5693a22f9e9df7344ecfb to your computer and use it in GitHub Desktop.

Select an option

Save witchfindertr/b7c5596eaed5693a22f9e9df7344ecfb to your computer and use it in GitHub Desktop.
flutter zaman
publishtime: DateTime.now().subtract(Duration(days: 10));
_getTime() {
String time;
DateTime now = DateTime.now();
Duration difference = now.difference(publishtime);
if (difference.inHours > 24) {
var format = DateFormat("dd.MM.yyyy");
time = format.format(publishtime);
} else {
time = difference.inHours.toString().replaceAll('-', '') + " hours ago";
}
return time;
}
DateTime dt1 = DateTime.parse("2021-12-23 11:47:00");
DateTime dt2 = DateTime.parse("2018-09-12 10:57:00");
Duration diff = dt1.difference(dt2);
print(diff.inDays);
//output (in days): 1198
print(diff.inHours);
//output (in hours): 28752
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment