Reputation: 111
I need the current time in milliseconds, so I use Calendar object to retrieve hours and minutes and convert them into milliseconds, but everytime it returns same value, that's the problem.
Calendar calendar = Calendar.getInstance();
int milliseconds = calendar.get(Calendar.HOUR_OF_DAY)*60*60*1000 +
calendar.get(Calendar.MINUTE);
Callendar.getTimeInMillis() and System doesn't work for me cause I can't convert them to daytime. What I need is current daytime but in milliseconds.
Upvotes: 1
Views: 278
Reputation: 1905
https://developer.android.com/reference/java/util/Date.html#getTime()
(new Date()).getTime())
https://developer.android.com/reference/java/lang/System.html#currentTimeMillis()
System.currentTimeMillis());
Both these methods returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
Upvotes: 1
Reputation: 75788
Read currentTimeMillis.
Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger.
long getTIME= calendar.getTimeInMillis();
Upvotes: 0
Reputation: 69689
try this use currentTimeMillis() it will Returns the current time in milliseconds.
Long time= System.currentTimeMillis();
Log.i("Time Class ", " Time value in millisecinds "+time);
Upvotes: 1
Reputation: 4141
You can use
java.util.Calendar.getTimeInMillis()
to get time in millis directly for that particular Calendar instance. If you just need Current time use
System.currentTimeMillis();
Upvotes: 2