views:

61

answers:

2

Does anyone know know how to programatically get the local date and time of the Android device? With that local date and time, does anyone know how to convert that to milliseconds from 1970 in UTC time?

+3  A: 

These are just standard Java solutions; nothing unique to Android:

// Get the local date/time
Calendar now = Calendar.getInstance();

// Return milliseconds from 1970 UTC
long milliseconds = now.getTimeInMillis();
Daniel Lew
Thanks, do you know I can get the same for a predefined date or date string instead of using Calendar.getInstance?
Zap
A: 

Another shorter way, if you just want the current timestamp in millis.

long now = System.currentTimeMillis();

http://developer.android.com/reference/java/lang/System.html#currentTimeMillis%28%29

Gubatron