NeuraCache
NeuraCache

Reputation: 14174

jodatime millis to date issue

I think I am missing something really simple but shouldn't this

long test = 1401894000; // GMT: Wed, 04 Jun 2014 15:00:00 GMT
DateTime dt = new DateTime(test);
Timber.d("TEST : %s", dt.toString("DD YYYY HH:mm"));

output

TEST : 04 2014 15:00

where what I see is

TEST : 17 1970 05:24

Im on Android

DateTimeZone.setDefault(DateTimeZone.UTC);

compile 'joda-time:joda-time:2.3'

Upvotes: 0

Views: 36

Answers (1)

Adam S
Adam S

Reputation: 16394

1401894000 is milliseconds since Jan 1, 1970.

Which, if we work out is:

  • 1401894000 / 1000 = 1401894 seconds
  • 1401894 / 60 = 23364.9 minutes
  • 23364.9 / 60 = 389.415 hours
  • 389.415 / 24 = 16.23 days

Which is between 5am and 6am on Jan 17 - which is the output you're seeing.

Upvotes: 1

Related Questions