Convert date and time to milliseconds in Android

前端 未结 4 1824
孤城傲影
孤城傲影 2021-01-03 20:31

I have Date and Time from DatePicker and TimePicker. Now i want to change the s

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-03 20:43

    You can create a Calendar object with the values from your DatePicker and TimePicker:

    Calendar calendar = Calendar.getInstance();
    calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth(), 
                 timePicker.getCurrentHour(), timePicker.getCurrentMinute(), 0);
    long startTime = calendar.getTimeInMillis();
    

提交回复
热议问题