Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert date and time to milliseconds in Android

I have Date and Time from DatePicker and TimePicker. Now i want to change the selected date and time into milliseconds. How can I do this???

For Example I have Date selected 2-5-2012 and Time is 20:43

Now I have to convert this Date Time into milliseconds something like

DateTimeInMilliseconds = 1234567890

like image 429
Ahmad Abbasi Avatar asked Nov 04 '12 21:11

Ahmad Abbasi


1 Answers

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(); 
like image 157
Sam Avatar answered Sep 28 '22 10:09

Sam