Getting wrong date in emulator?????

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

Getting wrong date in emulator?????

Postby xdebugx » Tue May 11, 2010 6:57 am

I'm trying to create a string with the current date, with this code:
Calendar currentDate=Calendar.getInstance();
string date=""+currentDate.get (java.util.Calendar.MONTH)+"-"+currentDate.get(java.util.Calendar.DAY_OF_MONTH)+"-"+currentDate.get(java.util.Calendar.YEAR);

It gives me the correct year and day, but the month is 1 month behind for some reason. I looked at the clock/date on the emulator and it says may 11, 2010, but the string from my code gives me 4-11-2010. What could be the problem? It may not be an emulator problem because it gives me the same wrong date on an actual device also.
xdebugx
Junior Developer
Junior Developer
 
Posts: 24
Joined: Fri Apr 02, 2010 4:06 am

Top

Re: Getting wrong date in emulator?????

Postby jsemler » Tue May 11, 2010 9:29 pm

xdebugx wrote:... but the month is 1 month behind for some reason. ...


Month number is zero relative. Jan is 0, Feb is 1, and etc.
jsemler
Junior Developer
Junior Developer
 
Posts: 24
Joined: Sun Apr 18, 2010 3:53 pm

Re: Getting wrong date in emulator?????

Postby xdebugx » Wed May 12, 2010 5:42 am

jsemler wrote:
xdebugx wrote:... but the month is 1 month behind for some reason. ...


Month number is zero relative. Jan is 0, Feb is 1, and etc.


Ohhhhh! That makes sense! Thanks!
xdebugx
Junior Developer
Junior Developer
 
Posts: 24
Joined: Fri Apr 02, 2010 4:06 am

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: No registered users and 5 guests