Sunrise / Check time
For my app I use a sunriseCalc-lib. This lib calculates the sunrise-time and returns a string like this 12:20. Is it possible to check if the current time is later than the sunrise time? I have the following code:
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 = newDateFo开发者_JS百科rmat.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
If you have Date objects already just use the before()
and after()
methods on those objects.
精彩评论