android - 如何从 flutter 中获取毫秒时间

标签 android flutter dart

我想从 openweathermap.org API 获取小时和分钟。在这个API中,日落的值为1570103293。现在我想从这个值获取日落时间。这是 API 的 JSON 值:

{
  "coord": {
    "lon": -122.08,
    "lat": 37.39
  },
  "weather": [
    {
      "id": 800,
      "main": "Clear",
      "description": "clear sky",
      "icon": "01d"
    }
  ],
  "base": "stations",
  "main": {
    "temp": 296.71,
    "pressure": 1013,
    "humidity": 53,
    "temp_min": 294.82,
    "temp_max": 298.71
  },
  "visibility": 16093,
  "wind": {
    "speed": 1.5,
    "deg": 350
  },
  "clouds": {
    "all": 1
  },
  "dt": 1560350645,
  "sys": {
    "type": 1,
    "id": 5122,
    "message": 0.0139,
    "country": "US",
    "sunrise": 1560343627,
    "sunset": 1560396563
  },
  "timezone": -25200,
  "id": 420006353,
  "name": "Mountain View",
  "cod": 200
}

最佳答案

您可以使用DateTime.fromMillisecondsSinceEpoch()。但'1560343627'是秒数(不是毫秒),所以你需要将它乘以1000:

DateTime.fromMillisecondsSinceEpoch(1560343627*1000)

关于android - 如何从 flutter 中获取毫秒时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58222090/

相关文章:

java - 一个传感器作为输出?

flutter - 使用Flutter打开数据库时出现意外的文字 'await'

按下按钮时不显示 flutter 对话框

dart - 如何在 Dart 2 中将 List<String> 更改为 List<dynamic>?

dart - 使用lawndart获取indexedDB中对象的值

android - 无法从 int 转换为 Android.Graphics.Color

c# - 更改禁用按钮上的文本颜色(自定义 ButtonRenderer)

flutter - 如何获取音频文件的长度而不在 Flutter/Dart 中播放

flutter - 在 Flutter 的 Bottom Sheet 单中创建一个下拉菜单

java - FacebookSDK 示例示例不适用于 Android 手机