Android Date worng conversion date into millis -


i got such issue. save date (yyyy,mm,dd). date need millisec representation, when call gettime() gives me wrong time. issue?

example :         date testdate= new date (2015,5,11); 

when try call date millisec, testdate.gettime()

result=61392117600000, must result=1433970000000 

note : 5 means jun, because counts 0

because in date class under package java.util; date method add year 1900 as

/**  * constructs new {@code date} initialized midnight in default {@code timezone} on  * specified date.  *  * @param year  *            year, 0 1900.  * @param month  *            month, 0 - 11.  * @param day  *            day of month, 1 - 31.  *  * @deprecated use {@link gregoriancalendar#gregoriancalendar(int, int, int)} instead.  */ @deprecated public date(int year, int month, int day) {     gregoriancalendar cal = new gregoriancalendar(false);     cal.set(1900 + year, month, day);     milliseconds = cal.gettimeinmillis(); } 

so need change

date testdate= new date (2015,5,11); 

to

date testdate= new date (115,5,11); 

recommended way use simpledateformat given below.

android convert date , time milliseconds


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -