@Test
public void times() throws ParseException{
long now = System.currentTimeMillis();
SimpleDateFormat sdfOne = new SimpleDateFormat("yyyy-MM-dd");
long overTime = (now - (sdfOne.parse(sdfOne.format(now)).getTime()))/1000;
//当前毫秒数
System.out.println(now);
//当前时间 距离当天凌晨 秒数 也就是今天过了多少秒
System.out.println(overTime);
//当前时间 距离当天晚上23:59:59 秒数 也就是今天还剩多少秒
long TimeNext = 24*60*60 - overTime;
System.out.println(TimeNext);
//当天凌晨毫秒数
System.out.println(sdfOne.parse(sdfOne.format(now)).getTime());
//当天凌晨日期
SimpleDateFormat sdfTwo = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.print(sdfTwo.format(sdfOne.parse(sdfOne.format(now)).getTime()));
}
Java 获取当前时间距离当天凌晨的秒数以及距离今天过完还剩多少秒
猜你喜欢
转载自blog.csdn.net/qq_40618664/article/details/102915473
今日推荐
周排行