Calendar cal = Calendar.getInstance();
Date time = cal.getTime();
System.out.println(time);

解决方案 »

  1.   

    看楼上的。JAVA中的Calendar类是对时间,日期的控制,熟悉这个类就可以了。还有Date也是。不过很多Date的方法都被Calendar取代了。
      

  2.   

    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;public  class GetDate {
      public String getDate() {
        SimpleDateFormat lFormat;
        Date date = null;
        Calendar MyDate = Calendar.getInstance();
        MyDate.setTime(new java.util.Date());
        date = MyDate.getTime();
        //格式可以自己根据需要修改
        lFormat =  new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String gRtnStr = lFormat.format(date);
        return gRtnStr;
        }
        //主方法测试用的
        /*public static void main(String[] args)
        {
          GetDate gd=new GetDate();
          String time=gd.getDate();
          System.out.println(time);
        }*/
    }
    在需要得到时间的程序中生成一个GetDate对象,然后调用它的getDate()方法就行了。