KonectarApp/lib/utils/dateformater.dart

41 lines
1.3 KiB
Dart

import 'package:intl/intl.dart';
class CustomDateFormatter {
DateTime convertStringToDate(String datestring) {
print("Date string : $datestring");
String char = "/";
if (datestring.contains("-")) {
char = "-";
}
List<String> datearray = datestring.split(char);
DateTime outputDate = DateTime(int.parse(datearray[2]),
int.parse(datearray[0]), int.parse(datearray[1]));
print("Output date : $outputDate");
return outputDate;
}
String convertDateTimeToDate(String datestring) {
print("Date string : $datestring");
List<String> datearray1 = datestring.split(' ');
print("Date string22 : $datearray1[0]");
List<String> datearray = datearray1[0].split('-');
DateTime outputDate = DateTime(int.parse(datearray[0]),
int.parse(datearray[1]), int.parse(datearray[2]));
final DateFormat formatter = DateFormat('dd-MM-yyyy');
print("Output date : $outputDate");
return formatter.format(outputDate);
}
String formatDate() {
final DateFormat formatter = DateFormat('yyyy-MM-dd hh:mm');
final String formatted = formatter.format(DateTime.now());
return formatted;
}
String formatYearDate(DateTime date) {
final DateFormat formatter = DateFormat('yyyy-MM-dd');
final String formatted = formatter.format(date);
return formatted;
}
}