Android set unix timestamp to a DatePicker

android, date, datepicker, java

Solution

As per comments, try using the `Calendar` class. You can also `Log` the outputs of `year`, `month`, and `day` to ensure they are correct.

Calendar c = Calendar.getInstance();
c.setTimeInMillis(((long) unixTimeStamp) * 1000L);
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
datePickerDateDue.init(year, month, day, null);

Problem

I'm trying to set a unix timestamp to an Android DatePicker using this code : ``` Date date = new Date(); date.setTime(((long)unixTimeStamp*1000)); datePickerDateDue.init(date.getYear(), date.getMonth(), date.getDay(), null); ``` But the Android DatePicker is set to a wrong value (1 Jan 1900) (((i don't like playing with dates...)))

Original source