时间的毫秒值long和日期格式date的转换

date->long

long time1 = System.currentTimeMillis();//获得系统当前时间
long time2 = date.getTime();//date为Date格式的变量

long->date

long time = (long)1514339596672;//报错,The literal 1514336569739 of type int is out of range 
1514339596672被默认识别为int格式,然后又超范围,因此:

long time=Long.valueOf("1514336569739");
Date date=new Date(time);
用这种方式解决了


猜你喜欢

转载自blog.csdn.net/GrassEva/article/details/78908845