开发者

Calendar returning the wrong time

The time displayed is way ahead of what I expected. I'开发者_StackOverflow社区m parsing a date string and turning it into milliseconds.

year = Integer.parseInt(m1.group(1));
mo = Integer.parseInt(m1.group(2));
day = Integer.parseInt(m1.group(3));
hr = Integer.parseInt(m1.group(4));
min = Integer.parseInt(m1.group(5));
sec = Integer.parseInt(m1.group(6));

and here I set the Calendar

Calendar cal = Calendar.getInstance();
cal.set(year, mo, day, hr, min, sec);
time = cal.getTimeInMillis();


If you check out the calendar documentation here, then visit here, you'll see that January is month 0. You'll want to change your code to mo = Integer.parseInt(m1.group(2))-1;


You should probably use DateFormatter to parse the date string (rather than rolling your own).

Other than that, make sure that you have the proper time zone and understand that month number one is February (not January).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜