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()))),
4
Try the following code:
DataCell(Text((DateTime.parse(e['start'].toString()).toLocal().toString()).replaceAll(".333", ""))),
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
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));
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
Click here to cancel reply.
4
Answers
Try the following code:
You can take this as an example:
This will remove the last 3 letters and ":" from it.
Another solution, you can also do this:
you can use the substring method on the string you get;
In particular, you can first calculate how the string should look like:
and then use the truncatedDateString variable in your DataCell:
Simply take the first 20 characters
or as mmcdon20 said use the intl package