做网站的公司金坛,wordpress 修改评论列表,三星网上商城发货速度,鞍山ui界面Instant
封装了从 1970-01-01T00:00:00Z 开始的秒数#xff0c;相当于时间戳。 主要有两个属性#xff1a;
private final long seconds;
private final int nanos;LocalDate
用于表示日期#xff0c;包括年、月、日#xff0c;例如 2017-12-03。 主要有三个属性…Instant
封装了从 1970-01-01T00:00:00Z 开始的秒数相当于时间戳。 主要有两个属性
private final long seconds;
private final int nanos;LocalDate
用于表示日期包括年、月、日例如 2017-12-03。 主要有三个属性
private final int year;
private final short month;
private final short day;LocalTime
用于表示时间包括时、分、秒例如 10:15:30。 主要有四个属性
private final byte hour;
private final byte minute;
private final byte second;
private final int nano; //纳秒LocalDateTime
符合 ISO-8601 时间表示标准用于表示日期和时间包括年、月、日、时、分、秒例如 2007-12-03T10:15:30。 localdatetime 不包含时区信息。 localdatetime 只有两个属性
private final LocalDate date; //日期
private final LocalTime time; //时间ZonedDateTime
包含日期、时间、时区信息例如 2007-12-03T10:15:3001:00 Europe/Paris 主要有三个属性
private final LocalDateTime dateTime; //时间
private final ZoneOffset offset; //相对于UTC的偏移量
private final ZoneId zone; //时区关联 #mermaid-svg-OMR5DtZ1AJRrln7Z {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-OMR5DtZ1AJRrln7Z .error-icon{fill:#552222;}#mermaid-svg-OMR5DtZ1AJRrln7Z .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-OMR5DtZ1AJRrln7Z .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-OMR5DtZ1AJRrln7Z .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-OMR5DtZ1AJRrln7Z .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-OMR5DtZ1AJRrln7Z .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-OMR5DtZ1AJRrln7Z .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-OMR5DtZ1AJRrln7Z .marker{fill:#333333;stroke:#333333;}#mermaid-svg-OMR5DtZ1AJRrln7Z .marker.cross{stroke:#333333;}#mermaid-svg-OMR5DtZ1AJRrln7Z svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-OMR5DtZ1AJRrln7Z .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-OMR5DtZ1AJRrln7Z .cluster-label text{fill:#333;}#mermaid-svg-OMR5DtZ1AJRrln7Z .cluster-label span{color:#333;}#mermaid-svg-OMR5DtZ1AJRrln7Z .label text,#mermaid-svg-OMR5DtZ1AJRrln7Z span{fill:#333;color:#333;}#mermaid-svg-OMR5DtZ1AJRrln7Z .node rect,#mermaid-svg-OMR5DtZ1AJRrln7Z .node circle,#mermaid-svg-OMR5DtZ1AJRrln7Z .node ellipse,#mermaid-svg-OMR5DtZ1AJRrln7Z .node polygon,#mermaid-svg-OMR5DtZ1AJRrln7Z .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-OMR5DtZ1AJRrln7Z .node .label{text-align:center;}#mermaid-svg-OMR5DtZ1AJRrln7Z .node.clickable{cursor:pointer;}#mermaid-svg-OMR5DtZ1AJRrln7Z .arrowheadPath{fill:#333333;}#mermaid-svg-OMR5DtZ1AJRrln7Z .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-OMR5DtZ1AJRrln7Z .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-OMR5DtZ1AJRrln7Z .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-OMR5DtZ1AJRrln7Z .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-OMR5DtZ1AJRrln7Z .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-OMR5DtZ1AJRrln7Z .cluster text{fill:#333;}#mermaid-svg-OMR5DtZ1AJRrln7Z .cluster span{color:#333;}#mermaid-svg-OMR5DtZ1AJRrln7Z div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-OMR5DtZ1AJRrln7Z :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 纳秒 Instant 秒 LocalTime 分 时 天 LocalDate 月 年 LocalDateTime ZonedDateTime 时区 时区偏移量 Instant,LocalDate,LocalTime,LocalDateTime 和 ZonedDateTime 共同的特征是都是不可变和线程安全的。
共同方法
now()
获取当前时间。
LocalDateTime localDateTime LocalDateTime.now(); //2023-10-29T15:18:15.186459200
LocalDate localDate LocalDate.now(); //2023-10-29of()
根据属性创建实例。
LocalDateTime localDateTimeLocalDateTime.of(2023,10,28,0,0); //2023-10-28T00:00from()
从 temporal 创建实例。
parse()
解析字符串创建实例。
LocalDateTime parse LocalDateTime.parse(2023-10-29T12:00:00); //2023-10-29T12:00get()
获取指定属性的数据例如分钟。
with()
对日期时间进行调整并返回调整后日期时间的副本。 主要存在两个方法一个是 with(TemporalAdjuster adjuster)通过调整器进行调整。底层调用的是 with(TemporalField field, long newValue) 方法。
LocalDateTime with localDateTime .with(Month.NOVEMBER) //先调整为11月.with(TemporalAdjusters.lastDayOfMonth()); //再调整为月底结果为 2023-11-30T00:00二是 with(TemporalField field, long newValue)通过将属性年、月、日等设置为新的值。
LocalDateTime localDateTimeLocalDateTime.of(2023,10,28,0,0);
LocalDateTime with localDateTime.with(ChronoField.MONTH_OF_YEAR, Month.NOVEMBER.getValue()); //将月设置为11月结果为2023-11-28T00:00plus()
将日期时间加上指定值并返回添加后的副本。 主要存在两种方法一是 plus(TemporalAmount amountToAdd)参数通常为实现 TemporalAmount 接口的 Duration 和 Period,分别代表一段时间和一段日期。底层调用的是 plus(long amountToAdd, TemporalUnit unit) 方法。
LocalDateTime localDateTimeLocalDateTime.of(2023,10,28,0,0);
LocalDateTime plus localDateTime.plus(Period.ofYears(1)); //将日期加上1年结果为2024-10-28T00:00二是 plus(long amountToAdd, TemporalUnit unit)通过将属性直接加上指定值。
LocalDateTime localDateTimeLocalDateTime.of(2023,10,28,0,0);
LocalDateTime plus localDateTime.plus(1, ChronoUnit.YEARS); //将日期加上1年结果为2024-10-28T00:00minus()
将日期时间减去指定值底层调用的是 plus(long amountToAdd, TemporalUnit unit)。只是将 amountToAdd 改成了负数。
until()
long until(Temporal endExclusive, TemporalUnit unit)endExclusive 为结束时间。 计算两个日期时间之间在某个属性方面的差值。
LocalDateTime localDateTimeLocalDateTime.of(2023,10,28,0,0);
LocalDateTime localDateTime2LocalDateTime.of(2023,11,28,0,0);
long until localDateTime.until(localDateTime2, ChronoUnit.MONTHS); //两个时间相差了1个月
long days localDateTime.until(localDateTime2, ChronoUnit.DAYS); //也等同于相差了31天format()
对代码进行格式化。
LocalDateTime localDateTimeLocalDateTime.of(2023,10,28,0,0);
DateTimeFormatter dateTimeFormatterDateTimeFormatter.ofPattern(yyyy-MM-dd);
String format localDateTime.format(dateTimeFormatter); //结果为2023-10-28isAfter()
判断当前时间是否晚于指定时间。
LocalDateTime localDateTimeLocalDateTime.of(2023,10,28,0,0);
LocalDateTime localDateTime2LocalDateTime.of(2023,11,28,0,0);
boolean after localDateTime.isAfter(localDateTime2); //false
boolean after1 localDateTime2.isAfter(localDateTime); //trueisBefore()
判断当前时间是否早于指定时间。
isEqual()
判断当前时间是否与指定时间相等。
相互转换 #mermaid-svg-lPF7o8KFMLaT6Exc {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-lPF7o8KFMLaT6Exc .error-icon{fill:#552222;}#mermaid-svg-lPF7o8KFMLaT6Exc .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-lPF7o8KFMLaT6Exc .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-lPF7o8KFMLaT6Exc .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-lPF7o8KFMLaT6Exc .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-lPF7o8KFMLaT6Exc .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-lPF7o8KFMLaT6Exc .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-lPF7o8KFMLaT6Exc .marker{fill:#333333;stroke:#333333;}#mermaid-svg-lPF7o8KFMLaT6Exc .marker.cross{stroke:#333333;}#mermaid-svg-lPF7o8KFMLaT6Exc svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-lPF7o8KFMLaT6Exc .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-lPF7o8KFMLaT6Exc .cluster-label text{fill:#333;}#mermaid-svg-lPF7o8KFMLaT6Exc .cluster-label span{color:#333;}#mermaid-svg-lPF7o8KFMLaT6Exc .label text,#mermaid-svg-lPF7o8KFMLaT6Exc span{fill:#333;color:#333;}#mermaid-svg-lPF7o8KFMLaT6Exc .node rect,#mermaid-svg-lPF7o8KFMLaT6Exc .node circle,#mermaid-svg-lPF7o8KFMLaT6Exc .node ellipse,#mermaid-svg-lPF7o8KFMLaT6Exc .node polygon,#mermaid-svg-lPF7o8KFMLaT6Exc .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-lPF7o8KFMLaT6Exc .node .label{text-align:center;}#mermaid-svg-lPF7o8KFMLaT6Exc .node.clickable{cursor:pointer;}#mermaid-svg-lPF7o8KFMLaT6Exc .arrowheadPath{fill:#333333;}#mermaid-svg-lPF7o8KFMLaT6Exc .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-lPF7o8KFMLaT6Exc .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-lPF7o8KFMLaT6Exc .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-lPF7o8KFMLaT6Exc .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-lPF7o8KFMLaT6Exc .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-lPF7o8KFMLaT6Exc .cluster text{fill:#333;}#mermaid-svg-lPF7o8KFMLaT6Exc .cluster span{color:#333;}#mermaid-svg-lPF7o8KFMLaT6Exc div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-lPF7o8KFMLaT6Exc :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} toLocalDateTime() toLocalDate() toLocalTime() toEpochSecond() toInstant() toLocalDate() toLocalTime() atZone(ZoneId) toEpochSecond(ZoneOffset) toInstant(ZoneOffset) atTime() toEpochSecond(LocalTime, ZoneOffset) atDate(LocalDate) toEpochSecond(LocalDate, ZoneOffset) atZone(ZoneId) toEpochMilli()/1000 ZonedDateTime LocalDateTime LocalDate LocalTime 时间戳 Instant 能看到转换方法主要以 to,at 为前缀并且 LocalDate,LocalTime,LocalDateTime 需要先转换为 ZonedDateTime 再转换为时间戳。