【问题标题】:How to convert String formatted date to timestamp in Flutter [duplicate]如何在 Flutter 中将字符串格式的日期转换为时间戳 [重复]
【发布时间】:2021-07-15 02:32:39
【问题描述】:

我有一个这种格式的字符串。

var stringDate = '27-04-2021 19:45' //dd-MM-yyyy HH:mm

我想将此字符串日期转换为时间戳 (millisecondsSinceEpoch)

【问题讨论】:

    标签: flutter dart


    【解决方案1】:
    import 'package:intl/intl.dart';
    
    getCustomFormattedDateTime(String givenDateTime, String dateFormat) {
        // dateFormat = 'MM/dd/yy';
        final DateTime docDateTime = DateTime.parse(givenDateTime);
        return DateFormat(dateFormat).format(docDateTime);
    }
    

    你可以用这个方法

    getCustomFormattedDateTime('2021-02-15T18:42:49.608466Z', 'MM/dd/yy');
    

    结果:

    21 年 2 月 15 日

    【讨论】:

    • 我需要时间和日期
    • 试试这个 getCustomFormattedDateTime('2021-02-15T18:42:49.608466Z', 'MM/dd/yy hh:mm:ss a');
    猜你喜欢
    • 1970-01-01
    • 2012-05-16
    • 1970-01-01
    • 2017-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    相关资源
    最近更新 更多