把时间转化为毫秒,把毫秒转化为时分秒
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类型的
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类型的
相关文章推荐
- poj 2492 A Bug's Life
- java 接口的引入
- 敏捷开发
- PHP+JQUEY+AJAX实现分页
- 对称矩阵和稀疏矩阵的压缩和转置
- Python爬虫辅助库BeautifulSoup4用法精要
- 接口特点
- 理解静态链接与动态链接
- AJAX笔记一创建XMLHttpRequest对象,以及XMLHttpRequest对象的常用属性
- 查看mysql的端口
- 鸟人的Android揭秘(10)——Init进程源代码分析(一)
- 微软的HLSL Shader Model 6.0 compiler要转向LLVM了,开源的节奏. Apple/Khronos都有各自计划
- spring MVC之构造ModelAndView对象
- c++时间转换与表示之03(与日期和时间相关的数据结构)
- Maven指南
- 文本文件与二进制文件区别
- 如何防止单例模式被 JAVA 反射攻击
- Android 判断触摸点是否在某个view的区域,解决子view与parent的touch事件冲突
- 接口成员特点
- openjudje 石头剪刀布