java,時間比較大小
阿新 • • 發佈:2019-01-31
try { SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); // System.out.println(sdf.format(new Date()));//00:49 Date now = sdf.parse(sdf.format(new Date())); Date beforeSunRise = sdf.parse("06:00"); Date sunRise = sdf.parse("08:00"); Date sunNoon = sdf.parse("14:00"); Date sunSet = sdf.parse("16:53"); Date afterSunSet = sdf.parse("23:53"); Long nowTime = now.getTime(); Long beforeSunRiseTime = beforeSunRise.getTime(); Long sunRiseTime = sunRise.getTime(); Long sunNoonTime = sunNoon.getTime(); Long sunSetTime = sunSet.getTime(); Long afterSunSetTime = afterSunSet.getTime(); System.out.println(nowTime); System.out.println(beforeSunRiseTime); System.out.println(sunRiseTime); System.out.println(sunNoonTime); System.out.println(sunSetTime); System.out.println(afterSunSetTime); // -25800000 // -7200000 // 0 // 21600000 // 31980000 // 57180000 } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); }