Last active
December 26, 2021 11:45
-
-
Save Jahidul007/a2dc80fdac4b7fd5b098b48dbd7afbf9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:intl/intl.dart'; | |
void main() { | |
var data = "12/26/2021 3:16 PM"; | |
String dateTime = getFormattedDateFromFormattedString( | |
value: data, | |
currentFormat: "MM/dd/yyyy hh:mm a", | |
desiredFormat: "yyyy-MM-ddTHH:mm:ss.mmmuuuZ"); | |
print(dateTime); //2021-12-15T15:16:00.000Z | |
} | |
getFormattedDateFromFormattedString( | |
{required value, | |
required String currentFormat, | |
required String desiredFormat, | |
isUtc = true}) { | |
DateTime? dateTime = DateTime.now(); | |
if (value != null || value.isNotEmpty) { | |
try { | |
dateTime = DateFormat(currentFormat).parse(value, isUtc); | |
} catch (e) { | |
print("$e"); | |
} | |
} | |
return dateTime!.toIso8601String(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment