stringToDate static method
Implementation
static DateTime? stringToDate(String dateString, {String? dateFormat, bool convertToLocal = false}){
DateTime? dateTime;
try {
final parsed = DateTime.parse(dateString);
dateTime = (convertToLocal && parsed.isUtc) ? parsed.toLocal() : parsed;
}catch(e){
logNUI("NUIDTUtil", "Failed to parse date directly with error : $e");
}
if(dateTime == null){
try{
if(!isNullOrEmpty(dateFormat)){
final parsed = DateFormat(dateFormat).parse(dateString);
dateTime = (convertToLocal && parsed.isUtc) ? parsed.toLocal() : parsed;
}
else{
final parsed = DateFormat(detectDateFormat(dateString)).parse(dateString);
dateTime = (convertToLocal && parsed.isUtc) ? parsed.toLocal() : parsed;
}
}catch(e){
logNUI("NUIDTUtil", "Failed to parse date dynamicly with error : $e");
}
}
return dateTime;
}