小编sim*_*imi的帖子

如何在 Dart 中格式化时间?

我尝试构建一个应用程序,该应用程序应该给出维也纳当地时间。我格式化了时间time = DateFormat.jm().format(),但现在我得到了一个类似的时间14:25 PM。我怎样才能删除PM,因为我不需要\xc2\xb4t?\n这是我尝试过的代码:

\n
class _MyHomePageState extends State<MyHomePage> {\n  void getTime() async {\n    String time;\n\n    Response response =\n        await get("http://worldtimeapi.org/api/timezone/Europe/Vienna");\n    Map data = jsonDecode(response.body);\n\n    String datetime = data["datetime"];\n    String offset = data["utc_offset"].substring(1, 3);\n    DateTime now = DateTime.parse(datetime);\n    now = now.add(Duration(hours: int.parse(offset)));\n    time = DateFormat.jm().format(now);\n    print(time);\n  }\n
Run Code Online (Sandbox Code Playgroud)\n

这是我得到的时间:

\n
I/flutter ( 9302): 12:43 PM\n
Run Code Online (Sandbox Code Playgroud)\n

dart flutter

3
推荐指数
1
解决办法
3808
查看次数

标签 统计

dart ×1

flutter ×1