@Test
public void test01() throws Exception {
long l = System.currentTimeMillis();
System.out.println(l);//获取当前毫秒值
SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd HH:mm:ss:SSS");
Thread.sleep(1000);
String format = sdf.format(new Date());
System.out.println(format);//获取当前时间
long time = sdf.parse(format).getTime();
System.out.println(time);//获取传入的String类型时间的毫秒值
System.out.println(Math.abs(l - time));//取绝对值
}
java时间转换、毫秒值获取
最新推荐文章于 2024-08-01 15:05:06 发布