1
This commit is contained in:
@@ -46,3 +46,16 @@ String formatSeconds(int seconds) {
|
||||
return '${twoDigits(m)}:${twoDigits(s)}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// 将 "HH", "HH:mm" 或 "HH:mm:ss" 转为当天 DateTime
|
||||
DateTime parseTime(String timeStr) {
|
||||
final now = DateTime.now();
|
||||
final parts = timeStr.split(':').map(int.parse).toList();
|
||||
|
||||
final hour = parts.length > 0 ? parts[0] : 0;
|
||||
final minute = parts.length > 1 ? parts[1] : 0;
|
||||
final second = parts.length > 2 ? parts[2] : 0;
|
||||
|
||||
return DateTime(now.year, now.month, now.day, hour, minute, second);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user