【问题标题】:i want to remove timestamp in date how can i solve this problem using flutter我想删除日期中的时间戳我如何使用颤振解决这个问题
【发布时间】:2022-10-24 03:57:10
【问题描述】:

我的程序输出是2022-11-17 15:06:59.422 我想删除这个timestamp。这是我的按钮代码:

 child: ElevatedButton(
                    onPressed: () async {
                      String startDate = startDateController.text;

                      String duration = durationController.text;

                      DateTime thirtyDaysFromNow =
                          DateTime.now().add(new Duration(days: 12));

                      setState(() {
                        startDate;
                        duration;
                        endDateController.text = thirtyDaysFromNow.toString();
                      });

                      print(thirtyDaysFromNow);
                    },
                    child: const Text("Save"),
                    style: ButtonStyle(
                        backgroundColor: MaterialStateProperty.all(
                            Color.fromARGB(255, 3, 89, 168))),

【问题讨论】:

    标签: flutter api dart datetime timestamp


    【解决方案1】:

    你可以在 Flutter 中使用 DateFormat 类:https://api.flutter.dev/flutter/intl/DateFormat-class.html

    要获得输出,您可以使用以下代码:

    final DateFormat formatter = DateFormat('yyyy-MM-dd');
    final String formatted = formatter.format(your date);
    

    【讨论】:

      猜你喜欢
      • 2021-01-19
      • 2021-07-02
      • 2019-12-23
      • 1970-01-01
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      • 2021-09-28
      • 1970-01-01
      相关资源
      最近更新 更多