Can I get milliseconds date value from a datepicker? (the milliseconds since 1970 value)

后端 未结 2 1147
生来不讨喜
生来不讨喜 2021-01-16 21:49

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?

相关标签:
2条回答
  • 2021-01-16 22:36

    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();
    }
    
    0 讨论(0)
  • 2021-01-16 22:47

    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();
    
    0 讨论(0)
提交回复
热议问题