Tipu Sultan
Tipu Sultan

Reputation: 1865

how to get time from millisecond in flutter

I want to get hours and minutes from openweathermap.org API. In this API the value of sunset is 1570103293. Now I want to get the sunset time from this value. Here is the JSON vale of the API:

{
  "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
}

Upvotes: 2

Views: 2808

Answers (1)

janstol
janstol

Reputation: 3157

You can use DateTime.fromMillisecondsSinceEpoch(). But '1560343627' is the number of seconds (not milliseconds), so you need to multiply it by 1000:

DateTime.fromMillisecondsSinceEpoch(1560343627*1000)

Upvotes: 4

Related Questions