Files
flutter_common/lib/utils/date_utils.dart
2025-11-22 15:19:34 +08:00

31 lines
671 B
Dart

import 'package:intl/intl.dart';
String formatDate(DateTime date) {
return DateFormat('yyyy-MM-dd').format(date);
}
String formatDateString(String date) {
return DateFormat('yyyy-MM-dd').format(DateTime.parse(date));
}
String formatTime(DateTime datetime) {
return DateFormat('yyyy-MM-dd HH:mm:ss').format(datetime);
}
bool isToday(DateTime? date) {
if (date == null) return false;
final now = DateTime.now();
return date.year == now.year &&
date.month == now.month &&
date.day == now.day;
}
bool isAfterToday(DateTime? date) {
if (date == null) return false;
if (!isToday(date)) return false;
return date.isAfter(DateTime.now());
}