0

I have a string in this format.

var stringDate = '27-04-2021 19:45' //dd-MM-yyyy HH:mm

I want to convert this String date to Timestamp (millisecondsSinceEpoch)

joisberg
  • 175
  • 2
  • 13

1 Answers1

2
import 'package:intl/intl.dart';

getCustomFormattedDateTime(String givenDateTime, String dateFormat) {
    // dateFormat = 'MM/dd/yy';
    final DateTime docDateTime = DateTime.parse(givenDateTime);
    return DateFormat(dateFormat).format(docDateTime);
}

You can use this method

getCustomFormattedDateTime('2021-02-15T18:42:49.608466Z', 'MM/dd/yy');

Result:

02/15/21

Christopher Moore
  • 15,626
  • 10
  • 42
  • 52
Aia Ashraf
  • 134
  • 5