fbmobile/lib/core/util/formatter_util.dart

20 lines
604 B
Dart
Raw Permalink Normal View History

2021-02-02 14:33:23 +00:00
import 'dart:math';
import 'package:intl/intl.dart';
class FormatterUtil {
/// Format epoch timestamp
static String formatEpoch(num millis) {
DateFormat dateFormat = DateFormat().add_yMEd().add_Hm();
2023-01-16 00:44:34 +00:00
return dateFormat
.format(DateTime.fromMillisecondsSinceEpoch(millis as int));
2021-02-02 14:33:23 +00:00
}
static String formatBytes(int bytes, int decimals) {
if (bytes <= 0) return "0 B";
const suffixes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
var i = (log(bytes) / log(1024)).floor();
2023-01-04 20:17:54 +00:00
return '${(bytes / pow(1024, i)).toStringAsFixed(decimals)} ${suffixes[i]}';
2021-02-02 14:33:23 +00:00
}
}