开发者

Java Date Issue On the Jboss Server

I have a web and mobile application. The application has kind of items that user can add using either the website or mobile app. Both add item forms have date field which is stored in t开发者_C百科he database in milliseconds.

User select date in mobile app using date picker and the format that is transferred to the server via web service is mm/dd/yyyy (08/03/2011).

When the data is received by the server, I have following code which converts this date into milliseconds.

DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
Calendar c = Calendar.getInstance();
c.setTime(df.parse("08/03/2011"));
c.add(Calendar.MONTH, 1);
long milliseconds = c.getTimeInMillis();

Although the above code works and inserts the data into database but when the website queries the data and show the date it's a month off. So if it's 08/03/2011 inserted by the mobile app, the website shows 07/03/2011. I wonder what's wrong here?


Arent you adding a month to the date in your code:

c.add(Calendar.MONTH, 1);


The first month in the Calendar is '0', basically means if you add one month to 08/03/2011 and print it using c.get(Calendar.MONTH) it will show '8'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜