Hello there i have this Datacells and i want to remove the last 3 numbers, here is my code line :
DataCell(Text((DateTime.parse(e['start'].toString()).toLocal().toString()))),
CodePudding user response:
Try the following code:
DataCell(Text((DateTime.parse(e['start'].toString()).toLocal().toString()).replaceAll(".333", ""))),
CodePudding user response:
You can take this as an example:
final text = "2022-06-12 16:34:45:333";
print(text.substring(0, text.length-4)); // 2022-06-12 16:34:45
This will remove the last 3 letters and ":" from it.
Another solution, you can also do this:
final text = "2022-06-12 16:34:45:333";
final asList = text.split(":");
asList.removeLast();
print(asList.join(":")); // 2022-06-12 16:34:45
CodePudding user response:
you can use the substring method on the string you get;
In particular, you can first calculate how the string should look like:
String dateString = DateTime.parse(e['start'].toString()).toLocal().toString();
String truncatedDateString = dateString.substring(0, dateString.length - 4);
and then use the truncatedDateString variable in your DataCell:
DataCell(Text(truncatedDateString));
CodePudding user response:
Simply take the first 20 characters
DateTime.parse(e['start'].toString()).toLocal().toString().substring(0,19); //2022-06-01 14:28:56
or as mmcdon20 said use the intl package
import 'package:intl/intl.dart';
...
DateTime now = DateTime.now();
String formattedDate = DateFormat('yyyy-MM-dd – kk:mm:ss').format(now); //2022-12-19 – 10:32:05