skip to Main Content

I am newbie in learning coding,

hi i want to show show the post created time like 2hours ago or 30 minutes ago like that, how to do that i only have the created time like 2023-01-13 10:35:52", how to convert that with current time or day

2

Answers


  1. you can use the difference method on date and time which give you the difference

    final date2 = DateTime.now();
    final difference = date2.difference(date);
    print(difference.inHours);
    

    from that you can get the difference in hours difference in minutes etc

    Login or Signup to reply.
  2. check the timeago package, it helps implementing what you need

    import 'package:timeago/timeago.dart' as timeago;
    
    main() {
        final date = DateTime.now().subtract(Duration(minutes: 50));
        print(timeago.format(date)); // 50 minutes ago
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search