MenoData / Time4J

Advanced date, time and interval library for Java with sun/moon-astronomy and calendars like Chinese, Coptic, Ethiopian, French Republican, Hebrew, Hijri, Historic Christian, Indian National, Japanese, Julian, Korean, Minguo, Persian, Thai, Vietnamese
GNU Lesser General Public License v2.1
424 stars 62 forks source link

[Question] How to get sunrise/sunset time? #949

Closed sblantipodi closed 2 years ago

sblantipodi commented 2 years ago

Hi, how can I get the sunrise/sunset time?

I know that it can be possible by knowing the GPS coordinates, but how can I get the GPS coordinates? :)

MenoData commented 2 years ago

You can calculate sunrise and sunset based on the class SolarTime. Its documentation contains examples how to do this task using geographic latitudes and longitudes.

But I can only speculate why you ask for getting these coordinates?! Maybe you are on an Android device. If so then you might start with this older issue and the link there.

sblantipodi commented 2 years ago

Thanks for the answer, I'm on WIndows/Linux and I don't see a "free" method to get the coordinates. :) Without coordinates it seems that I can't get the Sunrise/Sunset that is what I am searching for.

MenoData commented 2 years ago

If on a Windows/Linux-platform then it is clear that a computer cannot give you in general these coordinates. You will need any kind of GPS-enabled service or device. Or you simply ask the user for those coordinates via an input mask in the user interface which is my recommendation when ever your computer does not know where it is suited resp. located.