解决方案 »

  1.   

    获取出来的时间是从1970年1月1日开始计算的。Long time = System.currentTimeMillis();
            Date d = new Date(time);
            System.out.println(d.getHours());
            System.out.println(d.getMinutes());
            System.out.println(d.getSeconds());
    用上面的代码可以获取到时分秒
      

  2.   

    这种原因是由时区引起的,看看下面这个会自动转换好的package demo.spli;import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.TimeZone;
    public class ShowCurrentTime { /**
     * @显示当前时间
     * @2014.9.3
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    //获得系统的时间,单位为毫秒,转换为妙
    long totalMilliSeconds = System.currentTimeMillis();

     DateFormat dateFormatterChina = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM);//格式化输出
      TimeZone timeZoneChina = TimeZone.getTimeZone("Asia/Shanghai");//获取时区 这句加上,很关键。
      dateFormatterChina.setTimeZone(timeZoneChina);//设置系统时区
    long totalSeconds = totalMilliSeconds / 1000;

    //求出现在的秒
    long currentSecond = totalSeconds % 60;

    //求出现在的分
    long totalMinutes = totalSeconds / 60;
    long currentMinute = totalMinutes % 60;

    //求出现在的小时
    long totalHour = totalMinutes / 60;
    long currentHour = totalHour % 24;

    //显示时间
    System.out.println("总毫秒为: " + totalMilliSeconds);
    System.out.println(currentHour + ":" + currentMinute + ":" + currentSecond + " GMT");


    Date nowTime = new Date(System.currentTimeMillis());
    System.out.println(System.currentTimeMillis());
      SimpleDateFormat sdFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:dd");
      String retStrFormatNowDate = sdFormatter.format(nowTime);
      
      System.out.println(retStrFormatNowDate);
    }}
      

  3.   

    这是时区的原因,代码获取的是GMT+0的小时数。而中国在GMT+8,也就是加上8,就是中国的时间了。
      

  4.   

    系统给出的是GMT 格林尼治事件,我们是东八区,快了8个小时,结果对的。