开发者

The time my application displays does not change

I have a program which should display the current time. It displays the right time immediately after I install it to a phone. But after that, whenever I run the application, the time doesn't change at all.

Here's my code:

Calendar cal = new GregorianCalendar();
hour = cal.get(Calendar.HOUR);
minute = cal.get(Calendar.MINUTE);
second = cal.get(Calendar.SECOND);
year = cal.get(Calendar.YEAR);
month = 开发者_运维百科cal.get(Calendar.MONTH)+1;
day = cal.get(Calendar.DATE);
date = day+"_"+month+"_"+year+"_";
Current_Time = date+ hour + "_" + minute + "_" + second;


Shekhar... I had the same misunderstanding. When you create an instance of calendar, it represents the date at which it was instantiated and that state does not change! So, to get the current "date" you need to create a new instance.

JAL


You can write it as a method. Each call to create a new instance of the Calendar

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜