public enum TimeUnit extends Enum<TimeUnit>
文件名:TimeUnit.java
用途: 指定允许使用的时间单位
编码时间:2021年1月20日上午7:54:09
修改时间:2021年1月20日上午7:54:09
Enum Constant and Description |
---|
DAY
指向计算单位“日”,对应的时间单位为:日、d、D
|
HOUR
指向计算单位“时”,对应的时间单位为:时、h、H
|
MILLISECOND
指向计算单位“毫秒”,对应的时间单位为:毫秒、ms(所有字母不区分大小写)
|
MINUTE
指向计算单位“分”,对应的时间单位为:分、min(所有字母不区分大小写)
|
MONTH
指向计算单位“月”,对应的时间单位为:月、m、M
|
SECOND
指向计算单位“秒”,对应的时间单位为:秒、s、S
|
WEEK
指向计算单位“周”,对应的时间单位为:周、w、W
|
YEAR
指向计算单位“年”,对应的时间单位为:年、y、Y
|
Modifier and Type | Method and Description |
---|---|
ChronoUnit |
getChronoUnit()
用于返回单位在
ChronoUnit 的映射 |
long |
getToMillisNum()
用于返回单位转换为毫秒值所需的乘积
|
boolean |
isTimeUnit(String unit)
用于判断传入的单位是否符合当前枚举值
|
static TimeUnit |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static TimeUnit[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final TimeUnit YEAR
public static final TimeUnit MONTH
public static final TimeUnit WEEK
public static final TimeUnit DAY
public static final TimeUnit HOUR
public static final TimeUnit MINUTE
public static final TimeUnit SECOND
public static final TimeUnit MILLISECOND
public static TimeUnit[] values()
for (TimeUnit c : TimeUnit.values()) System.out.println(c);
public static TimeUnit valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic long getToMillisNum()
注意:在返回年、月单位的毫秒值乘积时,由于无法精确知道具体经过的闰年数与31天的月份数,故 年、月的毫秒值乘积返回取的是平均值,在精确计算时会存在误差
public ChronoUnit getChronoUnit()
ChronoUnit
的映射ChronoUnit
的映射public boolean isTimeUnit(String unit)
unit
- 单位Copyright © 2024. All rights reserved.