YearMonth
方法
adjustInto()涉及到Temporal先放着
atDay()
atEndOfMonth()
compareTo()也是差值
equals()也是值相同就返回true
format()
from()涉及到TemporalAccessor先放着
get()涉及到TemporalField先放着
getLong()涉及到TemporalField先放着
getMonth()
getMonthValue()
getYear()
hashCode()正常的hashCode和Year返回年不一样
isAfter()
isBefore()
isLeapYear()
isSupported()涉及到TemporalField和TemporalUnit先放着
isValidDay()
lengthOfMonth()
lengthOfYear()
minus()涉及到TemporalUnit和TemporalAmount先放着
minusMonths()
minusYears()
now()
of()
parse()要05不能5
plus()涉及到TemporalUnit和TemporalAmount先放着
plusMonths()
plusYears()
query()涉及到TemporalQuery先放着
range()涉及到TemporalField先放着
toString()
until()涉及到Temporal和TemporalUnit
with()涉及到TemporalAdjuster和TemporalField先放着
withMonth()
withYear()
import java.util.function.*;
import java.util.stream.*;
import java.util.*;
import java.math.*;
import static java.util.Calendar.*;
import java.time.*;
import java.time.format.*;
import java.time.chrono.*;
import java.time.temporal.*;
public class Test
{
public static void main(String[] args) throws Exception
{
//先练书上的例子
//YearMonth
YearMonth ym = YearMonth.of(111,11);
LocalDate localDate = ym.atDay(11);
System.out.println(localDate);
localDate = ym.atEndOfMonth();
System.out.println(localDate);
YearMonth ym1 = YearMonth.of(111,11);
YearMonth ym2 = YearMonth.of(111,11);
System.out.println(ym1.compareTo(ym2));
System.out.println(ym1.equals(ym2));
ym = YearMonth.of(111,8);
System.out.println(ym);
System.out.println(ym.format(DateTimeFormatter.ofPattern("yyyy年MM月")));
ym = YearMonth.of(2021,1);
System.out.println(ym.getMonth());
System.out.println(ym.getMonthValue());
System.out.println(ym.getYear());
ym1 = YearMonth.of(2222,11);
System.out.println(ym.hashCode());
System.out.println(ym1.hashCode());
ym1 = YearMonth.of(2011,2);
ym2 = YearMonth.of(2012,2);
System.out.println(ym1.isAfter(ym2));
System.out.println(ym1.isBefore(ym2));
System.out.println(ym1.isLeapYear());
System.out.println(ym2.isLeapYear());
System.out.println(ym1.isValidDay(29));
System.out.println(ym2.isValidDay(29));
System.out.println(ym1.lengthOfMonth());
System.out.println(ym2.lengthOfMonth());
System.out.println(ym1.lengthOfYear());
System.out.println(ym2.lengthOfYear());
ym1 = YearMonth.of(2020,10);
System.out.println(ym1);
ym1 = ym1.minusMonths(2);
System.out.println(ym1);
ym1 = ym1.minusYears(2);
System.out.println(ym1);
ym1 = YearMonth.now();
System.out.println(ym1);
Clock clock = Clock.systemUTC();
ym1 = YearMonth.now(clock);
System.out.println(ym1);
ZoneId zid = ZoneId.systemDefault();
ym1 = YearMonth.now(zid);
System.out.println(ym1);
ym = YearMonth.of(2011,12);
System.out.println(ym);
ym = YearMonth.of(2011,Month.MARCH);
System.out.println(ym);
ym = YearMonth.parse("2022-05");
System.out.println(ym);
ym= YearMonth.parse("2222年1月",DateTimeFormatter.ofPattern("yyyy年M月"));
System.out.println(ym);
ym = YearMonth.now();
ym = ym.plusMonths(2);
System.out.println(ym);
ym = ym.plusYears(1);
System.out.println(ym);
System.out.println(ym.toString());
ym = YearMonth.now();
System.out.println(ym);
ym = ym.withMonth(2);
System.out.println(ym);
ym = ym.withYear(1111);
System.out.println(ym);
}
}