I got such an issue. I save a Date (yyyy,mm,dd
). From this date I need to get its millisec
representation, but when I call getTime()
it gives me wrong time. Where is the issue?
Example :
Date testDate= new Date (2015,5,11);
When I try to call this date millisec, testDate.getTime()
result=61392117600000, but it must be result=1433970000000
Note : 5 means Jun, because it counts from 0
Because in the Date Class under package
java.util;
the date method add year from1900
asSo you need to change
to
Recommended way is to use
SimpleDateFormat
as given below.Android convert date and time to milliseconds