日の出、日の入り(Android版)
import java.util.Date; import java.util.Calendar; import java.text.SimpleDateFormat; import java.text.ParseException; ・ ・ ・ ・
Calendar calendar = Calendar.getInstance(); int c_year = calendar.get(Calendar.YEAR); int c_month = calendar.get(Calendar.MONTH) + 1; int c_day = calendar.get(Calendar.DAY_OF_MONTH);
String c_date = c_year + "/" + String.format("%1$02d",c_month) + "/" + String.format("%1$02d",c_day); String s_date = c_year + "/01/01"; double Days = 0; //1月1日からの通し日付 SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd"); try{ Date date1 = format.parse(c_date); Date date2 = format.parse(s_date); long datetime1 = date1.getTime(); long datetime2 = date2.getTime(); long one_date_time = 1000 * 60 * 60 * 24; long diffDays = (datetime1 - datetime2) / one_date_time; Days = (double)diffDays; }catch(Exception e){ }
double Keido = ******; double ido = ******; double IdoR= ido * Math.PI/180; double Day1 = 2*Math.PI*(Days - 81.5)/365; double Day2 = 2*Math.PI*(Days - 3)/365; double TimeEquation1 = -7.37*Math.sin(Day2); double TimeEquation2 = 9.86*Math.sin(2*Day1); double TimeEquation = TimeEquation1 + TimeEquation2; double SunDeclination = 0.4082*Math.sin(Day1); double Day_Time_min = 1440*(1-Math.acos(Math.tan(SunDeclination)*Math.tan(IdoR))/Math.PI); double Hosei_min = 0.8502*4/Math.sqrt(1-Math.sin(IdoR)*Math.sin(IdoR)/(Math.acos(SunDeclination)*Math.acos(SunDeclination))); double Culmination_Time = 720 - TimeEquation + 4*(135-Keido); //午前0時からの通し時間(分) double Sunrise_min = Culmination_Time - Day_Time_min/2-Hosei_min; double Sunset_min = Culmination_Time + Day_Time_min/2+Hosei_min; //日の出時刻 Sunrise_min = Math.ceil(Sunrise_min); int Sunrise_ji = (int)Math.floor(Sunrise_min / 60); int Sunrise_hun = (int)Sunrise_min - (Sunrise_ji*60); //日の入り時刻 Sunset_min = Math.ceil(Sunset_min); int Sunset_ji = (int)Math.floor(Sunset_min / 60); int Sunset_hun = (int)Sunset_min - (Sunset_ji*60);