system.currentTimeMillis() 获得当前的时间

package java.lang;下的system类中的public static long currentTimeMillis(),

该方法的作用是返回当前的计算机时间,时间的表达格式为当前计算机时间和GMT时间(格林威治时间)1970年1月1号0时0分0秒所差的毫秒数。 和 new Date().getTime()获取的时间戳相同;

可以直接把这个方法强制转换成date类型。

1、      long currentTime = System.currentTimeMillis();

            SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy年-MM月dd日-HH时mm分ss秒");

             Date date = new Date(currentTime);

             System.out.println(dateFormatter.format(date));

2、   long totalSeconds = totalMilliSeconds / 1000;  转换为秒

         //求出现在的秒 

         long currentSecond = totalSeconds % 60;

         //求出现在的分

         long totalMinutes = totalSeconds / 60;

         long currentMinute = totalMinutes % 60;

        //求出现在的小时

        long totalHour = totalMinutes / 60;

        long currentHour = totalHour % 24;

猜你喜欢

转载自blog.csdn.net/weixin_41898923/article/details/84976046