当前位置: 代码迷 >> Java Web开发 >> GregorianCalendar currentDay = new GregorianCalendar();该如何解决
  详细解决方案

GregorianCalendar currentDay = new GregorianCalendar();该如何解决

热度:409   发布时间:2016-04-17 12:25:07.0
GregorianCalendar currentDay = new GregorianCalendar();
GregorianCalendar currentDay = new GregorianCalendar();
int year= currentDay.get(Calendar.YEAR);
int month=currentDay.get(Calendar.MONTH);
int today=currentDay.get(Calendar.DAY_OF_MONTH);
int hour=currentDay.get(Calendar.HOUR_OF_DAY);
int minute=currentDay.get(Calendar.MINUTE_OF_DAY);
out.println(year+"年"+ (month+1)+"月"+today+"日"+hour+"时");


怎么总是提示分钟那一句有错误?

------解决方案--------------------
没有MINUTE_OF_DAY这个field
换MINUTE吧
------解决方案--------------------

<% 
request.setCharacterEncoding("gb2312");
GregorianCalendar currentDay = new GregorianCalendar(); 
int year= currentDay.get(Calendar.YEAR); 
int month=currentDay.get(Calendar.MONTH); 
int today=currentDay.get(Calendar.DAY_OF_MONTH); 
int hour=currentDay.get(Calendar.HOUR_OF_DAY); 
int minute=currentDay.get(Calendar.MINUTE); 
out.println(year+"年"+ (month+1)+"月"+today+"日"+hour+"时"+minute+"分"); 
%>
正如你说的,Calendar.MINUTE_OF_DAY 的类型 不能解析,我换成这个Calendar.MINUTE 就可以了。输出如下:


2008年4月3日17时2分