Java 獲取當前時間距離當天凌晨的秒數以及距離今天過完還剩多少秒

@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()));
	}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章