Convert a Regular Date to Julian Date and vice versa in Java

痴心易碎 提交于 2019-12-03 15:07:52

If you want 113029 ==> 29.01.2013 try

    String j = "113029";
    Date date = new SimpleDateFormat("Myydd").parse(j);
    String g = new SimpleDateFormat("dd.MM.yyyy").format(date);
    System.out.println(g);

output

29.01.2013
public static int[] julianToGregorian(double injulian) {
    int JGREG= 15 + 31*(10+12*1582);     
    int jalpha,ja,jb,jc,jd,je,year,month,day;
    double julian = injulian + 0.5 / 86400.0;
    ja = (int) julian
    if (ja>= JGREG) {
        jalpha = (int) (((ja - 1867216) - 0.25) / 36524.25);
        ja = ja + 1 + jalpha - jalpha / 4;
    }

    jb = ja + 1524;
    jc = (int) (6680.0 + ((jb - 2439870) - 122.1) / 365.25);
    jd = 365 * jc + jc / 4;
    je = (int) ((jb - jd) / 30.6001);
    day = jb - jd - (int) (30.6001 * je);
    month = je - 1;
    if (month > 12) month = month - 12;
    year = jc - 4715;
    if (month > 2) year--;
    if (year <= 0) year--;

    return new int[] {year, month, day};
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!