时间戳转成中文格式的时间
String formatCNDate(int dateValue, {bool withDetail:true}) {
/// dateValue: 需要格式的时间戳, withDetail: 是否返回时分秒
if(dateValue != null) {
var date = new DateTime.fromMillisecondsSinceEpoch(dateValue);
if(withDetail) {
return '${date.year}年${date.month}月${date.day}日 ${date.hour.toString().padLeft(2, "0")}:${date.minute.toString().padLeft(2, "0")}:${date.second.toString().padLeft(2, "0")}';
}else {
return '${date.year}年${date.month}月${date.day}日';
}
}else {
return '';
}
}
音视频播放时间格式化
String formatSeconds(int seconds) {
String toDigits(int n) => n.toString().padLeft(2, "0");
Duration duration = Duration(seconds: seconds)
String toDigitMinutes = twDigits(duration.inMinutes);
String toDigitSeconds = toDigits(duration.inSeconds.remainder(60));
return "$toDigitMinutes:$toDigitSeconds";
}
计算时间差
String workDuration (int endValue) {
/// endValue: 结束时间戳
var endTime = new DateTime.fromMillisecondsSinceEpoch(endValue);
var nowTime = new DateTime.now();
if(nowTime.isBefore(endTime)) {
var diff = nowTime.difference(endTime);
var diffTime = diff.toString().split('.')[0];
return diffTime.replaceAll('-', '');
}else {
return '00:00:00';
}
}