⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 juliandatestamp.java

📁 Jodd是一个开源的公用Java基础类库
💻 JAVA
字号:
package jodd.datetime;

import java.math.BigDecimal;

/**
 * Julian Date stamp, for high precision calculations. Julian date is a real
 * number and it basicly consist of two parts: integer and fraction. Integer
 * part carries date information, fraction carries time information.
 * <p>
 *
 * For calculations that will have time precision of 1e-3 seconds, both
 * fraction and integer part must have enough numerics in it. The problem is
 * that integer part is big and, on the other hand fractional is small, and
 * since final julian date is a sum of this two values, some fraction
 * numerals may be lost. Therefore, for higher precision both
 * fractional and intger part of julian date real number has to be
 * preserved.
 *
 * @see TimeUtil
 */
public class JulianDateStamp implements java.io.Serializable {

	/**
	 * Integer part of the Julian Date number.
	 */
	public int integer;
	

	/**
	 * Fraction part of the Julian Date number.
	 */
	public double fraction;


	/**
	 * Default constructor.
	 */
	public JulianDateStamp() {
	}

	/**
	 * Creates JuliandDateStamp from a <code>double</code>.
	 *
	 * @param jd     julian date
	 */
	public JulianDateStamp(double jd) {
		integer = (int)jd;
		fraction = jd - (double)integer;
	}

	/**
	 * Creates JuliandDateStamp from both integer and fractional part.
	 *
	 * @param i      integer part
	 * @param d      fractional part
	 */
	public JulianDateStamp(int i, double d) {
		integer = i;
		fraction = d;
	}

	/**
	 * Creates JuliandDateStamp from <code>BigDecimal</code>.
	 *
	 * @param bd     julian date
	 */
	public JulianDateStamp(BigDecimal bd) {
		double d = bd.doubleValue();
		integer = (int) d;
		bd = bd.subtract(new BigDecimal((double) integer));
		fraction = bd.doubleValue();
	}
	

	/**
	 * Returns <code>double</code> value of julian date number.
	 * <b>CAUTION</b>: double values may not be suit for precision math.
	 *
	 * @return julian date as double
	 */
	public double doubleValue() {
		return (double)integer + fraction;
	}

	/**
	 * Returns <code>BigDecimal</code> value of julian date number.
	 *
	 * @return julian date as double
	 */
	public BigDecimal toBigDecimal() {
		BigDecimal bd = new BigDecimal((double) integer);
		return bd.add(new BigDecimal(fraction));
	}

	/**
	 * Simple String conversion.
	 *
	 * @return julian integer as string
	 */
	public String toString() {
		String s = "" + fraction;
		int i = s.indexOf(".");
		s = s.substring(i + 1);
		return integer + "." + s;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -