31 lines
745 B
Dart
31 lines
745 B
Dart
import 'package:dart_date/dart_date.dart';
|
|
|
|
class Convert {
|
|
/// 隐藏字符串中间位
|
|
///
|
|
/// * [str] 要处理的字符串
|
|
/// * [start] 字符串从0开始保留位数
|
|
/// * [end] 末尾保留的长度
|
|
static String hideCenterStr(
|
|
String str, {
|
|
int start = 8,
|
|
int end = 6,
|
|
}) {
|
|
if (str.length <= start + end) {
|
|
return str;
|
|
}
|
|
return '${str.substring(0, start)}...${str.substring(str.length - end)}';
|
|
}
|
|
|
|
/// 时间戳转日期
|
|
///
|
|
/// [timestamp] 要转换的时间戳
|
|
/// [format] 日期格式
|
|
static String timeFormat(
|
|
int timestamp, {
|
|
String format = 'yyyy-MM-dd HH:mm:ss',
|
|
}) {
|
|
return DateTime.fromMillisecondsSinceEpoch(timestamp * 1000).format(format);
|
|
}
|
|
}
|