1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| import cds.astro.Astrotime;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;
class testJulianDay {
public static void main(String args[]) {
// select to_char(to_date('23/05/2008 10:32:45','DD/MM/YYYY HH24:MI:SS'),'JSSSSS') from dual;
// result = 245461037965
// current date = 23 May 2008 , 10H 32M 45s, julian day = 2454610
String oracleStr = "245461037965";
long julian = Integer.valueOf(oracleStr.substring(0, 7));
long second = Integer.valueOf(oracleStr.substring(7));
System.out.println("julian day = "+String.valueOf(julian));
System.out.println("second of the day = "+String.valueOf(second));
long offset = 2*3600*1000;
System.out.println("offset "+offset);
int[] ymd = new int[3];
Astrotime.JD2YMD(julian, ymd);
System.out.println("Y="+ymd[0]+" M="+ymd[1]+" d="+ymd[2]);
Calendar cal2 = new GregorianCalendar();
cal2.setTimeZone(TimeZone.getTimeZone("")); // GMT
cal2.setTimeInMillis(Astrotime.JD2ms(julian-0.5));
long as1 = cal2.getTimeInMillis()+second*1000;
System.out.println("Astr unix time = "+as1);
Calendar cal = new GregorianCalendar(2008, 4, 23, 10, 32, 45);
cal.setTimeZone(TimeZone.getTimeZone("")); // GMT
System.out.println("date unix time = "+cal.getTimeInMillis());
UTCDate d1 = new UTCDate(1970,1,1);
long dj = d1.getJulian();
long s= ((julian-dj)*24*3600+second)*1000;
System.out.println("UTC1 unix time = "+s);
System.out.println("time zone ="+cal2.getTimeZone());
System.out.println("time zone ="+cal.getTimeZone());
}
} |
Partager