0

I have to do some date manipulations [cringe] and I am trying to use ZonedDateTime for all its neat methods. My timestamp is in Unix time (epoch), and my API level is 16, how do I go about it?

For those using API 26+, the ZonedDateTime can be initiated using the class Instant, as such:

long timestamp = 1234567890;
Instant i = Instant.ofEpochSecond(timestamp);
ZonedDateTime z = ZonedDateTime.ofInstant(i, ZoneOffset.UTC);
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Caio Mar
  • 2,344
  • 5
  • 31
  • 37

1 Answers1

0

You would need to use a third-party library, such as ThreeTenABP from the indefatigable Jake Wharton.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Hmm, thanks. I am going to try to use the Calendar class before I do that. It would have been much simpler if we had 13 months of 4 weeks with 7 days and a day to kill. – Caio Mar Jul 22 '18 at 13:40