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我系统时间没有问题

解决方案 »

  1.   

    哎。getDay() 是获取星期的。today.getMonth() 是星期六,但是是用5代表6月的,也就是说 一月从0开始。
      

  2.   

    不能这样用
    你要输出指格式的日期字符串用SimpleDateFormat进行格式化Date today=new Date();
            String date= new SimpleDateFormat("yy-mm-dd").format(today);
            System.out.println("现在的日期是"+date);
      

  3.   

    @Deprecated
        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;
        }
      

  4.   


     normalize()
    gcal.
    @Deprecated这三个什么意思?
      

  5.   

    in english 
    意思是不赞成的,反对的,也就是说该方法已经过时了,不推荐使用
      

  6.   


     normalize()
    gcal.是?
      

  7.   

        private static final BaseCalendar gcal =
    CalendarSystem.getGregorianCalendar();
    楼主你读源代码吧?这种事情
    normalize()返回的是一个calendar对象。
      

  8.   

    你装jdk的时候,里面自带了一个 zip文件,那个文件就是java的源代码。