import java.util.Date;public class ttt {
public static void main(String[] args) {
Date today=new Date();
String date=today.getYear()+"-"+today.getMonth()+"-"+today.getDay();
System.out.println("现在的日期是"+date);
}
}这样不应该是输出今天的日期么?也就是说,Date today=new Date();不应该是以今天的日期新建Date实例么??我的电脑运行结果为 现在的日期是112-5-3我系统时间没有问题
public static void main(String[] args) {
Date today=new Date();
String date=today.getYear()+"-"+today.getMonth()+"-"+today.getDay();
System.out.println("现在的日期是"+date);
}
}这样不应该是输出今天的日期么?也就是说,Date today=new Date();不应该是以今天的日期新建Date实例么??我的电脑运行结果为 现在的日期是112-5-3我系统时间没有问题
你要输出指格式的日期字符串用SimpleDateFormat进行格式化Date today=new Date();
String date= new SimpleDateFormat("yy-mm-dd").format(today);
System.out.println("现在的日期是"+date);
public int getYear() {
return normalize().getYear() - 1900;
}
@Deprecated
public int getMonth() {
return normalize().getMonth() - 1; // adjust 1-based to 0-based
}
@Deprecated
public int getDay() {
return normalize().getDayOfWeek() - gcal.SUNDAY;
}
normalize()
gcal.
@Deprecated这三个什么意思?
意思是不赞成的,反对的,也就是说该方法已经过时了,不推荐使用
normalize()
gcal.是?
CalendarSystem.getGregorianCalendar();
楼主你读源代码吧?这种事情
normalize()返回的是一个calendar对象。