今天被 chat 坑了

1
2
3
4
5
6
7
# 错误的表达方式
int ms = 1000;

var format = DateFormat('HH:mm:ss');
var date = DateTime.fromMillisecondsSinceEpoch(ms);
print(format.format(date)); // 00:00:01

1
2
3
4
5
6
7
8
9
# 正确的方式
String timestampToTime(int timestamp) {
print("timestamp : ${timestamp}");
int hour = (timestamp / 3600).toInt();
int minute = (timestamp / 60 /60).toInt();
int second = (timestamp%60).toInt();

return "${hour.toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')}:${second.toString().padLeft(2, '0')}";
}