skip to Main Content

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()))),

enter image description here

4

Answers


  1. Try the following code:

    DataCell(Text((DateTime.parse(e['start'].toString()).toLocal().toString()).replaceAll(".333", ""))),
    
    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
  3. 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));
    
    Login or Signup to reply.
  4. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search