为什么当系统时间为零点零分零秒时,偶用new Timestamp(System.currentTimeMillis()),取到的总是2009-09-03之类的,米有小时分秒,用SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")格式化了也一样,偶怎么才能取到2009-09-03 00:00:00呢?

解决方案 »

  1.   

    你可以用new java.sql.Date(System.currentTimeMillis()),这个是没有时分秒的
      

  2.   

    Timestamp t = new Timestamp(System.currentTimeMillis());
    System.out.println(t.toString());
      

  3.   

    要是直接new完,不格式化,就输出,那就不会有~
    System.out.println(new java.sql.Date(System.currentTimeMillis()));
      

  4.   

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    long t = System.currentTimeMillis();
    t = t / (1000 * 3600 * 24) * (1000 * 3600 * 24) - TimeZone.getDefault().getRawOffset();
    System.out.println(sdf.format(new Timestamp(t)));