-1

I am trying to get a date, time and day from open weather API of a specific location and specific day using latitude and longitude. But it gives me a long integer something like this 1525974999. How can I retrieve date time and day from this?

Sohid Ullah
  • 75
  • 1
  • 1
  • 7

3 Answers3

0

Using Java 8 Time API:

Instant.ofEpochSecond(1525974999) // returns: 2018-05-10T17:56:39Z

Using old Java Date:

new Date(1525974999 * 1000L) // returns: Thu May 10 13:56:39 EDT 2018

I'm in Eastern US time zone

Andreas
  • 154,647
  • 11
  • 152
  • 247
0

It's probably in seconds. Try this:

Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(timeReturnedByAPI * 1000);

int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);

Here is the Calendar API: https://developer.android.com/reference/java/util/Calendar

Edit: You may want to use the version of getInstance that takes a time zone to get the local time.

Edit 2: Updated in response to comments.

Bakon Jarser
  • 703
  • 6
  • 20
0

The integer represents the amount of time it has been passed since January, 1, 1970. (Unix Time Stamp)

You can use a converter from unix time stamp or just do the math programmatically.