Here you can find the source of ISOToJulianDate(String dateObs)
Parameter | Description |
---|---|
dateObs | observation date as ISO format |
Parameter | Description |
---|---|
ParseException | When the dateObs format is wrong |
public static double ISOToJulianDate(String dateObs) throws ParseException
//package com.java2s; /* /*from ww w . j a va 2 s . c om*/ * Copyright (C) 2014 Jean-Christophe Malapert * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { /** * Transforms an ISO date to a julian date. * * @param dateObs observation date as ISO format * @return a Julian date * @throws ParseException When the dateObs format is wrong */ public static double ISOToJulianDate(String dateObs) throws ParseException { SimpleDateFormat sdf; if (dateObs.contains("T") && dateObs.contains(".")) { sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sss"); } else if (dateObs.contains("T")) { sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); } else if (dateObs.contains("-")) { sdf = new SimpleDateFormat("yyyy-MM-dd"); } else { sdf = new SimpleDateFormat("dd/MM/yy"); } Date date = sdf.parse(dateObs); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(date); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH) + 1; int day = calendar.get(Calendar.DAY_OF_MONTH); int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); double extra = (100.0 * year) + month - 190002.5; return (367.0 * year) - (Math.floor(7.0 * (year + Math.floor((month + 9.0) / 12.0)) / 4.0)) + Math.floor((275.0 * month) / 9.0) + day + ((hour + ((minute + (second / 60.0)) / 60.0)) / 24.0) + 1721013.5 - ((0.5 * extra) / Math.abs(extra)) + 0.5; } }