Java统计从1970年1月1日起的毫秒的数量表示日期。也就是说,例如,1970年1月2日,是在1月1日后的86,400,000毫秒。但是程序结果却不是如此,纳闷!!import java.text.ParseException;
import java.text.SimpleDateFormat;public class Test2 {
 
    
    public static void main(String[] args) {
        // TODO 
        String sDay = "1970-01-01";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");        try {
            java.util.Date d1 = sdf.parse(sDay);
            System.out.println(d1.getTime());
 
       } catch (ParseException e) {
           System.out.println(e);
       }    }
}
程序返回结果: 57600000请大家帮忙分析一下。

解决方案 »

  1.   

    只知道MFC中CTime类的时间是从1970.1.1开始的,java里我还没用到这个
      

  2.   

    我重新设置了格式 SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSSS");还是不行
      

  3.   

    Java统计的确是从1970年1月1日起的毫秒的数量表示日期
    但你这个是时区问题,你把你的时区改成GMT应该就行了
    和北京时间差8个小时,呵呵
      

  4.   

    import javax.swing.JOptionPane;public class ShowCurrentTime {
      public static void main(String[] args) {
        long totalMilliseconds = System.currentTimeMillis();
        long totalSeconds = totalMilliseconds / 1000;
        int currentSecond = (int)(totalSeconds % 60);
        long totalMinutes = totalSeconds / 60;
        int currentMinute = (int)(totalMinutes % 60);
        long totalHours = totalMinutes / 60;
        int currentHour = (int)(totalHours % 24);
       
        String output = "Current time is " + currentHour + ":"
               + currentMinute + ":" + currentSecond + "GMT";
        JOptionPane.showMessageDialog(null, output,
               "showCurrentTime",JOptionPane.INFORMATION_MESSAGE);
       }
    }
      

  5.   

    感谢wang_wei2007() 的答复!正确做法如下:……
            String sDay = "1970-01-01 GMT";
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd z");
    ……结果得到正确的0