Java 时间处理 ZoneDateTime

static方法

主要是用来构建时间戳ZoneDateTime对象

方法描述
from(TemporalAccessor temporal)从时间对象获取,TemporalAccessor就是time包下有关时间的类
now([ZoneId])当前时间,可以指定ZoneId,这样就不必使用withSame..那个函数了
of(int year, int month, int dayOfMonth, int hour, int minute, int second)从整数获取
ofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset)整形时间戳获取
ofInstant(Instant instant, ZoneId zone)Instant对象获取
of(LocalDateTime localDateTime, ZoneId zone)
of(LocalDate date, LocalTime time, ZoneId zone)这俩对象获取
parse(CharSequence text)从字符串获取,国际标准ISO格式的2007-12-03T10:15:30
parse(CharSequence text, DateTimeFormatter formatter)也可以自己指定

instance方法

1.获取时间组件
首先提供了一个get()通用方法,参数是ChronoField类型中的可用的字段
又提供了便捷的方法

int getDayOfMonth()
DayOfWeek getDayOfWeek()
int getDayOfYear()
int getHour()
long getLong(TemporalField field)
int getMinute()
Month getMonth()
int getMonthValue()
int getNano()
int getSecond()
int getYear()

2.比较
isBefore
isAfter

3.加减
plus plusSeconds
minus minusSeconds

4.更改时区
withZoneSameInstant(ZoneId zone)

5.转换
LocalDate toLocalDate()
LocalDateTime toLocalDateTime()
LocalTime toLocalTime()
OffsetDateTime toOffsetDateTime()
String toString()
参考:
https://docs.oracle.com/javase/8/docs/api/java/time/ZonedDateTime.html

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值