0

I have a DatePicker d; and I need to get the milliseconds value of the date. (the milliseconds since 1970 value)

how can I do it?

Cœur
  • 37,241
  • 25
  • 195
  • 267
NullPointerException
  • 36,107
  • 79
  • 222
  • 382

2 Answers2

7

Create a calender object and set the date and time from the date picker and today.getTimeInMillis().

onDateSet(...) {
    Calendar c = Calendar.getInstance();
    c.set(...);
    long mills = c.getTimeInMillis();
}
cx0der
  • 432
  • 5
  • 20
2

You just have to convert your result, using Calendar, or, more easily, Joda-Time

Here is an example with Joda-Time :

DateMidnight d = new DateMidnight(picker.getYear(), picker.getMonth(), picker.getDayOfMonth());
long millis = d.toDate().getTime();
Valentin Rocher
  • 11,667
  • 45
  • 59