如何在飞镖中将时间戳字符串从 24 小时格式转换为 12 小时格式? [英] How to convert time stamp string from 24 hr format to 12 hr format in dart?

查看:21
本文介绍了如何在飞镖中将时间戳字符串从 24 小时格式转换为 12 小时格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 Flutter 应用程序,我必须显示时间戳,但我从 api 得到的响应是 24 小时格式,我想在我的应用程序中以 12 小时格式显示时间.

I am working on flutter application where i have to show time stamps but the response i got from api is in 24 hr format and i want to display time in 12 hr format in my application.

我想以这种格式显示在应用程序上 您能帮我了解一下从 24 小时到 12 小时进行格式化的最简单方法吗?

And i want to display on application in this format Can you please help me regarding the easiest way of doing the formatting from 24 hr to 12 hr?

推荐答案

Dart intl 框架可帮助您将日期/时间格式化为您想要的任何类型.

Dart intl framework helps you to format date/time into any type you want.

https://pub.dev/packages/intl

特别是您的情况,您可以使用此代码.

Especially for your case, you can use this code.

DateFormat("h:mma").format(date);

这篇关于如何在飞镖中将时间戳字符串从 24 小时格式转换为 12 小时格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆