Date类用默认构造器就是当前机器时间

解决方案 »

  1.   

    Date类用默认构造器就是当前机器时间
      

  2.   

    import java.util.Date;public class DateExample1 {
        public static void main(String[] args) {
        // Get the system date/time
        Date date = new Date();    System.out.println(date.getTime());
        }
    }
      

  3.   

    Date now = new Date();如果要一些复杂操作的话就需GregorianCalendar类,看看文档,那里面有许多方法,估计够用
      

  4.   

    那改动系统时间呢?
    关注中……
    hehe,借用你的分
      

  5.   

    yuhan()的方的得不到你想要的,只能输出:1019554307040
    这是一个long型数据,指的从1970年元旦到现在地毫秒数。建议你看看GregorianCalendar类。
      

  6.   

    gflei说的对,看看这里的例子
    http://www.zdnet.com.cn/developer/code/story/0,2000081534,20030446-2,00.htm
      

  7.   

    import java.util.GregorianCalendar;
    import java.util.Date;
    import java.text.DateFormat;public class DateExample5 {    public static void main(String[] args) {
            DateFormat dateFormat =
            DateFormat.getDateInstance(DateFormat.FULL);        // Create our Gregorian Calendar.
            GregorianCalendar cal = new GregorianCalendar();        // Set the date and time of our calendar
            // to the system's date and time
            cal.setTime(new Date());        System.out.println("System Date: " +
            dateFormat.format(cal.getTime()));        // Set the day of week to FRIDAY
            cal.set(GregorianCalendar.DAY_OF_WEEK,
            GregorianCalendar.FRIDAY);
            System.out.println("After Setting Day of Week to Friday: " +
            dateFormat.format(cal.getTime()));        int friday13Counter = 0;
            while (friday13Counter <= 10) {            // Go to the next Friday by adding 7 days.
                cal.add(GregorianCalendar.DAY_OF_MONTH, 7);            // If the day of month is 13 we have
                // another Friday the 13th.
                if (cal.get(GregorianCalendar.DAY_OF_MONTH) == 13) {
                    friday13Counter++;
                    System.out.println(dateFormat.format(cal.getTime()));
                }
            }
        }
    }
      

  8.   

    这个也不错!import java.text.DateFormat;
    import java.util.Date;public class DateExample4 {    public static void main(String[] args) {
            Date date = new Date();        DateFormat shortDateFormat =
            DateFormat.getDateTimeInstance(
            DateFormat.SHORT,
            DateFormat.SHORT);        DateFormat mediumDateFormat =
            DateFormat.getDateTimeInstance(
            DateFormat.MEDIUM,
            DateFormat.MEDIUM);        DateFormat longDateFormat =
            DateFormat.getDateTimeInstance(
            DateFormat.LONG,
            DateFormat.LONG);        DateFormat fullDateFormat =
            DateFormat.getDateTimeInstance(
            DateFormat.FULL,
            DateFormat.FULL);        System.out.println(shortDateFormat.format(date));
            System.out.println(mediumDateFormat.format(date));
            System.out.println(longDateFormat.format(date));
            System.out.println(fullDateFormat.format(date));
        }
    }
      

  9.   

    完整例子import java.util.*;
    import java.text.*;
    public class test
    {
    public static void main(String[] args)
    {
    Date aDate = new Date();//取得系统时间
    DateFormat fmt = DateFormat.getDateTimeInstance();
    String dateString = fmt.format(aDate);//用DateFormat对象fmt格式化Date对象aDate并赋值给String变量dateString
    System.out.println(dateString);
    }
    }
      

  10.   

    你可以对DateFormat.getDateTimeInstance()的参数进行改造,指定日期和时间的格式或者调用DateFormat的其他方法,比如getDateInstance()和getTimeInstance()