对于我的应用程序,我使用SunriseCalc-lib。
此lib计算日出时间,并返回类似于12:20的字符串。
是否可以检查当前时间是否晚于日出时间?
我有以下代码:

        Location location = new Location("52.3496752", "4.6211921");
        DateFormat newDateFormat = new SimpleDateFormat("HH:mm");
        SunriseSunsetCalculator calculator = new SunriseSunsetCalculator(location, "Europe/Berlin");
        Calendar date = Calendar.getInstance();

        Date dawn = newDateFormat.parse(calculator.getOfficialSunriseForDate(date));
        Date dusk = newDateFormat.parse(calculator.getOfficialSunsetForDate(date));

最佳答案

new Date().after(dawn)

http://download.oracle.com/javase/6/docs/api/java/util/Date.html#after%28java.util.Date%29

http://download.oracle.com/javase/6/docs/api/java/util/Date.html#before%28java.util.Date%29

关于java - 日出/检查时间,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4695496/

10-12 02:25