Advertisement
rachmadi

Utilities.dart

Mar 11th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.72 KB | None | 0 0
  1. import 'package:intl/intl.dart';
  2.  
  3. class Utilities{
  4.  
  5.   String convertTimestamp(int timestamp) {
  6.     var now = new DateTime.now();
  7.     var format = new DateFormat('HH:mm a');
  8.     var date = new DateTime.fromMicrosecondsSinceEpoch(timestamp * 1000);
  9.     var diff = date.difference(now);
  10.     var time = '';
  11.  
  12.     if (diff.inSeconds <= 0 || diff.inSeconds > 0 && diff.inMinutes == 0 ||
  13.         diff.inMinutes > 0 && diff.inHours == 0 || diff.inHours > 0 &&
  14.         diff.inDays == 0) {
  15.       time = format.format(date);
  16.     } else {
  17.       if (diff.inDays == 1) {
  18.         time = diff.inDays.toString() + 'DAY AGO';
  19.       } else {
  20.         time = diff.inDays.toString() + 'DAYS AGO';
  21.       }
  22.     }
  23.  
  24.     return time;
  25.   }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement