怎么获得系统时间啊?不要这种格式阿System.currentTimeMillis() 
        要当前年+当前月+当前日+当前小时+当前分+当前秒+当前毫秒+当前微秒啊
xxxx年+xx月+xx日+小时+分+秒+毫秒+微秒啊
有办法吗?

解决方案 »

  1.   

    DateFormat df = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
    System.out.println(df.format(new Date()));
      

  2.   

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
    System.out.println(df.format(new Date()));
      

  3.   

    呵呵,楼主看来是刚学java要多看书了,加油
      

  4.   

    /**
         * 将YYYYMMDD格式的串转换成YYYY-MM-DD格式,反函数为dateToStr
         * @param   date  YYYYMMDD格式的串
         *
         * @return: YYYY-MM-DD格式的串
         */
        public static String strToDate(String date){
            StringBuffer temp = new StringBuffer();
            temp.append(date.substring(0,4)).append("-").append(date.substring(4,6));
            temp.append( "-").append(date.substring(6,8));
            return temp.toString();
        }    /**
         * 将YYYY-MM-DD格式的串转换成YYYYMMDD格式,反函数为strToDate
         * @param   date  YYYY-MM-DD格式的串
         *
         * @return: YYYYMMDD格式的串
         */
        public static String dateToStr(String date){
            StringBuffer temp = new StringBuffer();
            temp.append(date.substring(0,4)).append(date.substring(5,7));
            temp.append(date.substring(8,10));
            return temp.toString();
        }
      

  5.   

    楼上的不是多此一举吗,干吗不用SimpleDateFormat
    而且第二个dateToStr,只需要return date.replaceAll("-","")就可以了
      

  6.   

    谢谢 believefym(暮色,miss,迷失,miss) 啊!还能加上更小的时间单位吗?
    怎么写阿?
      

  7.   

    谢谢 believefym(暮色,miss,迷失,miss) 啊!还能加上更小的时间单位吗?
    怎么写阿?
      

  8.   

    谢谢 believefym(暮色,miss,迷失,miss) 啊!还能加上更小的时间单位吗?
    怎么写阿?
      

  9.   

    看了api,好像到毫秒级吧,微妙的不知道如何处理了