您的位置:首页 > 其它

把时间转化为毫秒,把毫秒转化为时分秒

2016-12-29 22:35 417 查看
    1、把年月日时分秒转化为毫秒,计算两个时间段有多少毫秒

             long time1 = 0;

             long time2 = 0;

             long time=0;

SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

             Calendar cal = Calendar.getInstance();

                    cal.setTime(“时间段1”);  

                    time1 = cal.getTimeInMillis();  

                    cal.setTime(“时间段2”);

                    time2 = cal.getTimeInMillis(); //以毫秒计算

                    time=time2-time1;

2、将毫秒转化为时分秒

             SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");//初始化Formatter的转换格式。      

             formatter.setTimeZone(TimeZone.getTimeZone("GMT+00:00"));

             String hms = formatter.format(time);  //time为转化的毫秒数,long类型的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: