How to parse date fields ?
ajonno opened this issue · 2 comments
ajonno commented
rdunlocked18 commented
Go ahead Use this to convert both time and date!
Formated Date Will be like this 5-12-1992:
static String? formatSheetDate(String? dateGot) {
if (dateGot == null || dateGot == '') return null;
final dateSome = DateTime.fromMillisecondsSinceEpoch(
((double.parse(dateGot) - 25569) * 86400000).toInt(),
isUtc: true);
var dateTime = DateTime.parse(dateSome.toString());
var formatDate = "${dateTime.day}-${dateTime.month}-${dateTime.year}";
return formatDate;
}
Formated Time Will be like this 08:20 AM :
static String? formatSheetTime(String? timeGot) {
if (timeGot == null || timeGot == '') return null;
final dateSome = DateTime.fromMillisecondsSinceEpoch(
((double.parse(timeGot) - 25569) * 86400000).toInt(),
isUtc: true);
var dateTime = DateTime.parse(dateSome.toString());
var formattedTime = DateFormat('hh:mm a').format(dateTime);
return formattedTime;
}
jeff9315 commented
Perfect @rdunlocked18 ... Just what I needed.