How to format DateTime in Flutter

前端 未结 9 1781
悲哀的现实
悲哀的现实 2020-12-04 10:28

I am trying to display the current DateTime in a Text widget after tapping on a button. The following works, but I\'d like to change the format.

9条回答
  •  孤街浪徒
    2020-12-04 11:12

    Try out this package, Jiffy, it also runs on top of Intl, but makes it easier using momentjs syntax. See below

    import 'package:jiffy/jiffy.dart';   
    
    var now = Jiffy().format("yyyy-MM-dd HH:mm:ss");
    

    You can also do the following

    var a = Jiffy().yMMMMd; // October 18, 2019
    

    And you can also pass in your DateTime object, A string and an array

    var a = Jiffy(DateTime(2019, 10, 18)).yMMMMd; // October 18, 2019
    
    var a = Jiffy("2019-10-18").yMMMMd; // October 18, 2019
    
    var a = Jiffy([2019, 10, 18]).yMMMMd; // October 18, 2019
    

提交回复
热议问题