Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:intl/intl.dart';
- class Utilities{
- String convertTimestamp(int timestamp) {
- var now = new DateTime.now();
- var format = new DateFormat('HH:mm a');
- var date = new DateTime.fromMicrosecondsSinceEpoch(timestamp * 1000);
- var diff = now.difference(date);
- var time = '';
- print('diff in days: ${diff.inDays}');
- if (diff.inSeconds <= 0 || diff.inSeconds > 0 && diff.inMinutes == 0 ||
- diff.inMinutes > 0 && diff.inHours == 0 || diff.inHours > 0 &&
- diff.inDays == 0) {
- time = format.format(date);
- } else {
- if (diff.inDays == 1) {
- time = diff.inDays.toString() + 'DAY AGO';
- } else {
- time = diff.inDays.toString() + 'DAYS AGO';
- }
- }
- return time;
- }
- }
Add Comment
Please, Sign In to add comment