SexagesimalFormatter in Java

2025年5月9日 | 阅读 2 分钟

Sexagesimal 是一种测量系统,其中角度以度、分和秒为单位进行测量。在 Java 中,SexagesimalFormatter 是一个 formatter 类,属于 herschel.share.fltdyn.math 包。它扩展了 Object。它用于解析和格式化 sexagesimal 值。基数为 60 的值称为 sexagesimal 值。该类的目的是以小时-分钟-秒 (HMS) 或度-分-秒 (DMS) 的形式表示时间中使用的角度。除此之外,我们还可以将其用于时间。

Java SexagesimalFormatter 类构造函数

SexagesimalFormatter 类定义了以下两个构造函数

构造函数描述
SexagesimalFormatter(SexagesimalFormatter.Mode mode)它创建一个 SexagesimalFormatter。
SexagesimalFormatter(String separators, boolean hours, boolean nonNegative)它创建一个自定义的 SexagesimalFormatter。

Java SexagesimalFormatter 类方法

方法描述
format(boolean sign, int hrsDeg, int min, int sec, int frac, int fracWidth)它将度、分、小时和秒格式化为 sexagesimal 字符串。
formatDegrees(double degrees)它将度值格式化为 sexagesimal 字符串。
formatRadians(double radians)它将弧度值格式化为 sexagesimal 字符串。
formatSeconds(double seconds)它将秒值格式化为 sexagesimal 字符串。
parseDegrees(String string)它将 sexagesimal 字符串解析为度值。
parseFields(String string)它将 sexagesimal 字符串解析为值数组。
parseRadians(String string)它将 sexagesimal 字符串解析为弧度值。
parseSeconds(String string)它将 sexagesimal 字符串解析为秒值。
setDecimals(int decimals)它设置格式化秒的小数位数,并进行四舍五入。
setOmitDecimalPoint(boolean enable)它指定在格式化时省略小数点。
setSeparatorBeforePoint(boolean enable)它指定秒分隔符在小数点之前。
setShowLeadingZeros(boolean enable)使用前导零进行格式化。
setShowPlusSign(boolean enable)它使用显式“+”符号表示正角度进行格式化。
toString()它返回该对象的字符串表示形式。

除了这些方法之外,它还继承了 Object 类中的方法。