packageyhtest;importjava.util.Calendar;publicclassgetNowTime{staticCalendarnowtime;publicgetNowTime(){nowtime=Calendar.getInstance();}publicstaticStringtime(){intmonth=no...
package yhtest;
import java.util.Calendar;
public class getNowTime {
static Calendar nowtime;
public getNowTime() {
nowtime=Calendar.getInstance();
}
public static String time()
{
int month=nowtime.get(Calendar.MONTH)+1;
int year=nowtime.get(Calendar.YEAR);
int day=nowtime.get(Calendar.DATE);
int hour=nowtime.get(Calendar.HOUR);
int minute=nowtime.get(Calendar.MINUTE);
String nowtime1;
nowtime1=year+"-"+month+"-"+day+" "+hour+":"+minute;
//System.out.println(nowtime);
return nowtime1.toString();
}
public static void main(String[] args) {
System.out.println(getNowTime.time());
}
}
为什么总是包异常啊?只要我直接掉用静态方法就会报异常,如果我先实列化再掉用这个方法就不会有异常,什么情况啊?
展开