I need to convert this date format Sun Dec 24 2023 21:00:00 GMT+0000 (Coordinated Universal Time) to yyyy:MM:dd HH:mm in flutter what is the actual date format Patten i can use for convert to custom date format?
I need to convert this date format Sun Dec 24 2023 21:00:00 GMT+0000 (Coordinated Universal Time) to yyyy:MM:dd HH:mm in flutter what is the actual date format Patten i can use for convert to custom date format?
3
Answers
call function -> convertUniversalTimeToCustomFormat('Sun Dec 24 2023 21:00:00 GMT+0000 (Coordinated Universal Time)')
convertUniversalTimeToCustomFormat(String dateTime, {String currentDateFormat = 'EEE MMM dd yyyy HH:mm:ss zzz', String newDateFormat = 'yyyy:mm:dd hh:mm'}) { var date = ''; try { date = DateFormat(newDateFormat).format(DateTime.parse(DateFormat(currentDateFormat).parse(dateTime).toString())); } catch (e) { date = 'Invalid date'; } return date; }
Use DateFormat from
intl
package to format dates:First, make sure to include the intl package in your pubspec.yaml file:
dependencies:
You can the below code as per need
String dateString = "Sun Dec 24 2023 21:00:00 GMT+0000 (Coordinated Universal Time)";