【问题标题】:How to print UTC time, Europe Time Zone & American Timezone in Dart [closed]如何在 Dart 中打印 UTC 时间、欧洲时区和美国时区 [关闭]
【发布时间】:2021-07-30 13:18:43
【问题描述】:

我正在尝试在 Dart 中打印 TimeStamp,我想在以下时区打印当前时间:

  • 欧洲
  • 美国
  • UTC

【问题讨论】:

  • 到目前为止你尝试过什么?你需要展示你的进步

标签: flutter datetime dart timestamp datetime-format


【解决方案1】:

创建一个方法:

DateTime timeIn([Duration duration = Duration.zero]) {
  return DateTime.now().toUtc().add(duration);
}

用法:

timeIn(); // UTC or GMT
timeIn(Duration(hours: 5, minutes: 30)); // +5.30 (IST)
timeIn(Duration(hours: 2)); // +2.00 (CEST)
timeIn(Duration(hours: -4)); // -4.00 (EDT)
timeIn(Duration(hours: -5)); // -5.00 (EST)
timeIn(Duration(hours: -7)); // -7.00 (MST)
timeIn(Duration(hours: -8)); // -8.00 (PST)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-29
    • 2020-04-21
    • 2022-07-26
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 2012-10-21
    相关资源
    最近更新 更多