java - Convert regular date and time to Julian date and vice versa -
i working on program calculate sunrise , sunset times. how convert yyyymmddhhmmss julian date? need date precise. it'll great if there can example such conversions. code julian date:
calendar cnow = calendar.getinstance(); calendar cjan1 = calendar.getinstance(); double julianjan1_2014_12_00_00 = 2456659; cjan1.set(2014, 0, 0, 12, 0); date djan1 = cjan1.gettime(); date dnow = cnow.gettime(); long ljan1 = djan1.gettime(); long lnow = dnow.gettime(); double diffday = (lnow - ljan1) / 1000 / 60 / 60 / 24; double juliandate = diffday + julianjan1_2014_12_00_00;
code sunrise , sunset (formula wikipedia):
calendar cnow = calendar.getinstance(); calendar cjan1 = calendar.getinstance(); double julianjan1_2014_12_00_00 = 2456659; cjan1.set(2014, 0, 0, 12, 0); date djan1 = cjan1.gettime(); date dnow = cnow.gettime(); long ljan1 = djan1.gettime(); long lnow = dnow.gettime(); double diffday = (lnow - ljan1) / 1000 / 60 / 60 / 24; double juliandate = diffday + julianjan1_2014_12_00_00; double nstar = juliandate - 2451545.0009 - (-longi) / 360; double n = nstar + 0.5; double jstar = 2151545.0009 + (-longi) / 360 + n; double m = (357.5291 + 0.98560028 * (jstar - 2451545)) % 360; double c = 1.9148 * math.sin(m/57.3) + 0.0200 * math.sin(2 * m/57.3) + 0.0003 * math.sin(3 * m/57.3); double ecliplong = (m + 102.9372 + c + 180) % 360; double jtrans = jstar + 0.0053 * math.sin(m/57.3) - 0.0069 * math.sin(2 * ecliplong/57.3); double sindecsun = math.sin(ecliplong/57.3) * math.sin(23.45/57.3); double coshran = math.sin(-0.83/57.3) - math.sin(lat/57.3) * sindecsun; double sunset = 2451545.0009 + (math.acos(coshran/57.3) + (-longi)) / 360 + n + 0.0053 * math.sin(m/57.3) - 0.0069 * math.sin(2 * ecliplong/57.3); double sunrise = jtrans - (sunset - jtrans); sunrise = sunrise; sunset = sunset;
try this
gregoriancalendar c = new gregoriancalendar(); c.setgregorianchange(new date(system.currenttimemillis() + 100000000)); simpledateformat df = new simpledateformat("yyyy-mm-dd mm:hh:ss"); df.setcalendar(c); string d = df.format(new date());
Comments
Post a Comment