0
  final exp = RegExp(
    '^([1-9]|([012][0-9])|(3[01])) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d\d\d\d (20|21|22|23|[0-1]?\d):[0-5]?\ds+');

My input string is 14 Aug 2020 12:20,14 Aug 2020 12:20:30

I need to convert the above string value to date and time, Please help. I tried using the above code but I'm stuck in somewhere

Akash
  • 425
  • 2
  • 7
  • 21

1 Answers1

0

Something like this using the intl package:

import 'package:intl/intl.dart';

void main() {
  const input = "14 Aug 2020 12:20,14 Aug 2020 12:20:30";
  input.split(',').map(parseDateTime).forEach(print);
  // 2020-08-14 12:20:00.000
  // 2020-08-14 12:20:30.000
}

DateTime parseDateTime(String input) {
  try {
    return DateFormat('dd MMM y HH:mm:ss').parse(input);
  } on FormatException {
    return DateFormat('dd MMM y HH:mm').parse(input);
  }
}

You can read more about the DateFormat class here: https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html

julemand101
  • 28,470
  • 5
  • 52
  • 48