Java Today today()

Here you can find the source of today()

Description

today

License

Apache License

Declaration

public static final double today() 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static final long GREGORIAN_EPOCH = 1721425;

    public static final double today() {
        java.util.Calendar dte = java.util.Calendar.getInstance();
        dte.setTime(new java.util.Date());
        return date(dte.get(java.util.Calendar.YEAR), dte.get(java.util.Calendar.MONTH) + 1,
                dte.get(java.util.Calendar.DATE));
    }/*ww w .  j  av  a2  s  . c  om*/

    public static final double date(double year, double month, double day) {
        if (!isFinite(day) || !isFinite(month) || !isFinite(year)) {
            return Double.NaN;
        }
        if (year < 1900) {
            year += 1900;
        }
        if (year > 9999) {
            return Double.NaN;
        }
        double adj_year = year;
        double adj_month = month;
        if (month > 0) {
            adj_year = year + Math.floor((month - 1) / 12);
            adj_month = ((month - 1) % 12) + 1;
        } else if (month < 0) {
            double tmp = Math.ceil((-month) / 12);
            adj_year = year - tmp;
            adj_month = adj_month + tmp * 12;
        }
        double res = (gregorian_to_jd((long) adj_year, (long) adj_month, (long) day) - 2415020);
        if (res > 59) {
            return res + 1;
        }
        return res;
    }

    public static final boolean isFinite(double x) {
        return !(Double.isInfinite(x) || Double.isNaN(x));
    }

    public static final long gregorian_to_jd(long year, long month, long day) {
        return GREGORIAN_EPOCH + (365 * (year - 1)) + ((year - 1) / 4) + (-((year - 1) / 100)) + ((year - 1) / 400)
                + ((((367 * month) - 362) / 12) + ((month <= 2) ? 0 : (leap_gregorian(year) ? -1 : -2)) + day);
    }

    public static final boolean leap_gregorian(long year) {
        return ((year % 4) == 0) && (!(((year % 100) == 0) && ((year % 400) != 0)));
    }
}

Related

  1. today()
  2. today()
  3. today()
  4. today()
  5. today()
  6. today()
  7. today()
  8. today()
  9. today()