java8日期時間

1. LocalDate、LocalTime、LocalDateTime函數

LocalDateTime的方法code

static LocalDateTime now()
static of(int year, int month, int dayOfMonth, int hour, int minute, int second)
LocalDateTime plusYears(long years)
LocalDateTime minusYears(long years)
int getYear()
int getMonthValue()
int getDayOfMonth()
int getHour()
int getMinute()
getSecond()

String format(DateTimeFormatter formatter)
static LocalDateTime parse(CharSequence text, DateTimeFormatter formatter)


//方法返回此LocalDateTime的副本,其中包含每日更改的日期。
LocalDateTime withDayOfMonth(int dayOfMonth) //方法返回此LocalDateTime的副本,其中包含每日更改的日期。
LocalDateTime with(TemporalAdjuster adjuster)

2. Instant : 時間戳。 (使用 Unix 元年 1970年1月1日 00:00:00 所經歷的毫秒值)orm

static Instant now()
OffsetDateTime atOffset(ZoneOffset offset)
int getNano()
static Instant ofEpochSecond(long epochSecond) //使用1970-01-01T00:00:00Z的紀元中的秒來獲取Instant的實例

ZoneOffset的方法接口

static ZoneOffset ofHours(int hours)

3. Duration的方法 :get

// 用於計算兩個「時間」間隔
//public final class Instant implements Temporal
static Duration between(Temporal startInclusive, Temporal endExclusive)
long getSeconds()
long toMillis()

Period的方法 :it

//用於計算兩個「日期」間隔
static Period between(LocalDate startDateInclusive, LocalDate endDateExclusive)
int getYears()
int getMonths()
int getDays()

4. TemporalAdjuster : 時間校訂器,函數式接口io

 

TemporalAdjusters的方法form

static TemporalAdjuster next(DayOfWeek dayOfWeek)
//自定義:下一個工做日
LocalDateTime ldt5 = ldt.with((l) -> {
	LocalDateTime ldt4 = (LocalDateTime) l;
	
	DayOfWeek dow = ldt4.getDayOfWeek();
	
	if(dow.equals(DayOfWeek.FRIDAY)){
		return ldt4.plusDays(3);
	}else if(dow.equals(DayOfWeek.SATURDAY)){
		return ldt4.plusDays(2);
	}else{
		return ldt4.plusDays(1);
	}
});

5. DateTimeFormatter : 解析和格式化日期或時間
 class

static DateTimeFormatter ofPattern(String pattern)
String format(TemporalAccessor temporal)

6.ZonedDate、ZonedTime、ZonedDateTime : 帶時區的時間或日期sso

相關文章
相關標籤/搜索