【问题标题】:Changing Date and time Time formate from Json Response in dart?从飞镖中的Json响应更改日期和时间时间格式?
【发布时间】:2021-04-11 08:50:51
【问题描述】:

你好朋友我是飞镖从 Api 获取数据的新手,现在我想格式化这个日期时间。以这种方式 => 2021 年 3 月 20 日上午 11:36.. 虽然 json 响应以这种方式出现 =>":"2021-03-20 11:36:00

这是我的 json 完整响应文件,请检查回答问题?

"message":"Data fetched successfully",
   "data":[
      {
         "id":1,
         "public_id":"ed0042ca-5a14-476b-9b65-66461efa81ae",
         "title":"LIVE CONCERT",
         "image":"https:\/\/livinghopemobile.com\/public\/storage\/event\/200321_113705_image.png",
         "datetime":"2021-03-20 11:36:00",  <=
         "description":"LIVE CONCERT",
         "created_at":"2021-03-20T06:37:05.000000Z",
         "updated_at":"2021-03-29T07:18:50.000000Z"
      }
   ]
}

【问题讨论】:

    标签: flutter dart


    【解决方案1】:
     String date = DateFormat("MMM dd, yyyy hh:mm a").format(DateTime.parse("2021-03-20 11:36:00"));
     print(date); // =>Mar 20, 2021 11:36 AM
    

    【讨论】:

      【解决方案2】:

      试试这个

       var date = "2021-03-24T08:57:47.812" 
       var dateTime =  DateTime.parse("$date");
       var stdTime =  DateFormat('MMM d, yy hh:mm a').format(dateTime).toString();
      

      【讨论】:

        【解决方案3】:

        试试这个

        var time = DateTime.parse(data[0]['datetime']);
        

        然后你可以在这里查看日期格式列表Here

        var myTime =  DateFormat('MMM d, yy hh:mm a').format(time);
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2019-11-11
          • 1970-01-01
          • 1970-01-01
          • 2021-02-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多