我正试图获得凤凰城的日出和日落时间。
我正在使用:https://github.com/mikereedell/sunrisesunsetlib-java
package sunriseSunsetCalculator;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import com.luckycatlabs.sunrisesunset.SunriseSunsetCalculator;
import com.luckycatlabs.sunrisesunset.dto.Location;
public class getSunriseSunet
{
public static void main (String[] args) throws IOException
{
Location location = new Location("33.4500", "-112.0667");
SunriseSunsetCalculator calculator = new SunriseSunsetCalculator(location, "Phoenix");
Date today = Calendar.getInstance().getTime();
String officialSunrise = calculator.getOfficialSunriseForDate(Calendar.getInstance());
String officialSunset = calculator.getOfficialSunriseForDate(Calendar.getInstance());
System.out.println(today + " officialSunrise : " + officialSunrise);
System.out.println(today + " officialSunset : " + officialSunset);
}
}
输出
Sat Mar 14 21:35:51 MST 2015 officialSunrise:13:39
Sat Mar 14 21:35:51 MST 2015 officialSunset:13:39
有关日出和日落时间不正确的任何建议吗?
答案 0 :(得分:0)
对于日落时间,请致电getOfficialSunsetForDate(Calendar.getInstance());
答案 1 :(得分:0)
我不确定您的Phoenix的timeZoneIdentifier是否正确。你可以把它改成: America / Phoenix
此外,您应该在正确的时区创建日历:
SunriseSunsetCalculator calculator = new SunriseSunsetCalculator(lcation, "US/Phoenix");
Calendar today = new GregorianCalendar(TimeZone.getTimeZone("US/Phoenix"));
String sunrise = calculator.getOfficialSunriseForDate(today);
String sunset = calculator.getOfficialSunsetForDate(today);
答案 2 :(得分:0)
package sunriseSunsetCalculator;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import com.luckycatlabs.sunrisesunset.SunriseSunsetCalculator;
import com.luckycatlabs.sunrisesunset.dto.Location;
public class getSunriseSunet
{
public static void main (String[] args) throws IOException
{
Location location = new Location("33.4500", "-112.0667");
SunriseSunsetCalculator calculator = new SunriseSunsetCalculator(location, "US/Arizona");
Calendar today = new GregorianCalendar(TimeZone.getTimeZone("US/Arizona"));
String officialSunrise = calculator.getOfficialSunriseForDate(today);
String officialSunset = calculator.getOfficialSunsetForDate(today);
System.out.println(" officialSunrise : " + officialSunrise);
System.out.println(" officialSunset : " + officialSunset);
}
}
从http://tutorials.jenkov.com/java-date-time/java-util-timezone.html
获取时区输出:
officialSunrise:06:39
官方日历:18:36