如何以本地时间显示 UTC 时间

How to display UTC time in local time

在我的 flutter 应用程序中,我从服务器获取 UTC 格式的预约时间。 我想按当地时间显示。

有没有办法在 flutter 中将 UTC 时间转换为本地时间?

Dart 内置了 DateTime 类型,它提供了很多方便的方法来在时间格式之间进行转换。

void main() {
  var utc = DateTime.parse("2020-06-11 17:47:35 Z");
  print(utc.toString());             // 2020-06-11 17:47:35.000Z
  print(utc.isUtc.toString());       // true
  print(utc.toLocal().toString());   //2020-06-11 23:17:35.000
}