Palagerini
Palagerini

Reputation: 159

Android Calender.getTimeInMillis() units?

I am using Android's Calendar object and I am using the getTimeInMillis() method, but when I look at the Value it gives me it is a really long number. I am trying to replicate this format but I don't know how as when I take the current time in 24 hour mode and convert it to milliseconds I am completely off.

Example:

Calendar.getTimeInMillis() : at 11:46 pm = 1,349,585,220,205

Time at 11:46 pm using formula[(23 * 60 * 60 * 1000) + (46 * 60 * 1000)] = 85,560,000

I'm wondering if there is some kind of formula the calendar is using to convert the current time to Milliseconds and how I can replicate this.

Thank you!

Upvotes: 2

Views: 2281

Answers (1)

I82Much
I82Much

Reputation: 27336

It's the number of milliseconds since the epoch, 1/1/1970. See this article on Unix time.

1,349,585,220,205 milliseconds / (1000 * 3600) = number of hours = 374884.7833902778
374884.7833902778 hours / 24 = 15620.19930792824 days
15620.19930792824 days / 365 days = 42.79506659706368 years

1970 + 42 years = 2012

(This is not precise due to not taking into account daylight savings time. Use a real datetime library!)

Upvotes: 3

Related Questions