How can I get the current date (w/o hour and minutes)?

前端 未结 7 1584
攒了一身酷
攒了一身酷 2020-12-05 12:33

All I can see in the documentation is Datetime.now() but it returns the Timespan, I need just the date.

相关标签:
7条回答
  • 2020-12-05 13:34

    If you want only the date without the timestamp. You can take the help of intl package.

    main() {
        var now = new DateTime.now();
        var formatter = new DateFormat('yyyy-MM-dd');
        String formattedDate = formatter.format(now);
        print(formattedDate); // 2016-01-25
    } 
    

    This requires the intl package:

    dependencies:
      intl: ^0.16.1
    

    And finally import:

    import 'package:intl/intl.dart';
    
    0 讨论(0)
提交回复
热议问题