SHARE
TWEET

Utilities.dart

rachmadi Mar 11th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top