我试图构建一个应该从维也纳给出当地时间的应用程序。我用格式化时间time = DateFormat.jm().format()
,但是现在我得到了类似的时间14:25 PM
。我不需要PM,该如何删除它?这是我尝试的代码:
class _MyHomePageState extends State<MyHomePage> {
void getTime() async {
String time;
Response response =
await get("http://worldtimeapi.org/api/timezone/Europe/Vienna");
Map data = jsonDecode(response.body);
String datetime = data["datetime"];
String offset = data["utc_offset"].substring(1, 3);
DateTime now = DateTime.parse(datetime);
now = now.add(Duration(hours: int.parse(offset)));
time = DateFormat.jm().format(now);
print(time);
}
这是我得到的时间:
I/flutter ( 9302): 12:43 PM
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句