练习java文档LocalDate

LocalDate
变量
EPOCH
MAX
MIN
方法
adjustInto()涉及到Temporal先放着
atStartOfDay() 还有一个方法涉及到ZoneId和ZoneDateTime先放着
atTime() 除了一个涉及到offsetTime类的重载方法先放着
compareTo() 如果两个LocalDate的年不同,返回年的差,如果年相同,返回月的差,以此类推
datesUntil()
equals() 只要日期相等就返回true
format()
from() 涉及到TemporalAccessor,先放着
get()涉及到TemporalField 先放着
getChronology() 涉及到IsoChronology类,这个类不熟
getDayOfMonth()
getDayOfWeek()
getDayOfYear()
getEra()
getLong()涉及TemporalField先放着
getMonth()
getMonthValue()
getYear()
hashCode() 随着天数的增加而增加,2021-12-19:4139795,2021-12-20:4139796
isAfter()
isBefore()
isEqual()
isLeapYear()
isSupported() 涉及到TemporalField和TemporalUnit先放着
lengthOfMonth()
lengthOfYear()
minus() 涉及到TemporalUnit和TemporalAmount先放着
minusDays()
minusMonths()
monusWeeks() 减去一周,其实就是减去7天
minusYears()
now()
of()
ofEpochDay()
ofInstant()
ofYearDay()
parse() 单个参数只能是2021-11-11这种格式
plus()也是涉及TemporalUnit和TemporalAmount先放着
plusDays()
plusMonths()
plusWeeks()
plusYears()
query() 涉及到TemporalQuery先放着
range() 涉及到TemporalField先放着
toEpochSeconds()涉及到ZoneOffset先放着
toString()
until() 还有一个方法涉及TemporalUnit,先放着
with() 涉及TemporalAdjuster和TemporalField先放着
withDayOfMonth()
withDayOfYear()
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
	{

		//先练书上的例子
		LocalDate localDate = LocalDate.ofYearDay(2014,146);
		System.out.println(localDate);
		localDate = LocalDate.of(2014,Month.MAY,21);
		System.out.println(localDate);
		//LocalDate
		//先看看变量
		System.out.println(LocalDate.EPOCH);
		System.out.println(LocalDate.MAX);
		System.out.println(LocalDate.MIN);

		//方法
		LocalDate ld = LocalDate.now();
		LocalDateTime ldt = ld.atStartOfDay();
		System.out.println(ld);
		System.out.println(ldt);
		
		ld = LocalDate.now();
		ldt = ld.atTime(10,20);
		System.out.println(ld);
		System.out.println(ldt);
		ldt = ld.atTime(10,20,30);
		System.out.println(ldt);
		ldt = ld.atTime(10,20,30,100);
		System.out.println(ldt);
		
		LocalTime lt = LocalTime.of(12,24);
		ldt = ld.atTime(lt);
		System.out.println(ldt);

		ld = LocalDate.of(2055,10,14);
		LocalDate ld2 = LocalDate.of(2055,5,2);
		System.out.println(ld.compareTo(ld2));

		ld = LocalDate.of(2029,2,3);
		Stream st = ld.datesUntil(LocalDate.of(2038,2,3));
		st = st.skip(10);
		System.out.println(st.findFirst());

		ld = LocalDate.of(2010,10,10);
		Period period = Period.of(10,0,0);
		st = ld.datesUntil(LocalDate.of(2090,10,15),period);
		st = st.skip(1);
		System.out.println(st.findFirst());

		ld = LocalDate.of(2010,10,10);
		ld2 = LocalDate.of(2010,10,11);
		System.out.println(ld.equals(ld2));

		ld = LocalDate.of(3125,10,10);
		DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy MM dd");
		System.out.println(ld.format(dtf));
		
		ld = LocalDate.of(2222,1,1);
		IsoChronology ic = ld.getChronology();
		System.out.println(ic);
		System.out.println(ic.getId());

		ld = LocalDate.of(2222,2,2);
		System.out.println(ld.getDayOfMonth());

		ld = LocalDate.now();
		System.out.println(ld);
		System.out.println(ld.getDayOfWeek());
		System.out.println(ld.getDayOfYear());
		System.out.println(ld.getEra().getValue());

		ld = LocalDate.now();
		System.out.println(ld.getMonth().getValue());
		System.out.println(ld.getMonth());
		System.out.println(ld.getMonthValue());
		System.out.println(ld.getYear());

		ld = LocalDate.of(2021,12,19);
		ld2 = LocalDate.of(2021,12,20);
		System.out.println(ld.hashCode());
		System.out.println(ld2.hashCode());
		

		ld = LocalDate.of(2011,1,1);
		ld2 = LocalDate.of(2022,1,1);
		System.out.println(ld.isAfter(ld2));
		System.out.println(ld.isBefore(ld2));
		System.out.println(ld.isEqual(ld2));
		System.out.println(ld.isEqual(LocalDate.of(2011,1,1)));
		System.out.println(ld.isLeapYear());
		System.out.println(LocalDate.of(2000,3,20).isLeapYear());


		ld = LocalDate.now();
		ld2 = LocalDate.of(2000,3,20);
		System.out.println(ld.lengthOfMonth());
		System.out.println(ld2.lengthOfMonth());
		System.out.println(ld.lengthOfYear());
		System.out.println(ld2.lengthOfYear());

		ld = LocalDate.now();
		ld = ld.minusDays(10);
		System.out.println(ld);

		ld = ld.minusMonths(6);
		System.out.println(ld);
		ld = ld.minusWeeks(1);
		System.out.println(ld);
		ld = ld.minusYears(1);
		System.out.println(ld);

		Clock clock = Clock.systemUTC();
		ld = LocalDate.now(clock);
		System.out.println(ld);
		
		ZoneId  zid = ZoneId.systemDefault();
		ld = LocalDate.now(zid);
		System.out.println(ld);
		
		ld = LocalDate.of(2111,10,10);
		System.out.println(ld);
		ld = LocalDate.of(2001,Month.MAY,10);
		System.out.println(ld);

		ld = LocalDate.ofEpochDay(100);
		System.out.println(ld);

		Instant instant = Instant.now();
		instant = instant.minusSeconds(3600*25);
		ld = LocalDate.ofInstant(instant, ZoneId.systemDefault());
		System.out.println(ld);

		ld = LocalDate.ofYearDay(2222,100);
		System.out.println(ld);

		ld = LocalDate.parse("2021-11-11");
		System.out.println(ld);

		ld = LocalDate.parse("2021年11月11日",DateTimeFormatter.ofPattern("yyyy年MM月dd日"));
		System.out.println(ld);

		ld = LocalDate.now().plusDays(15);
		System.out.println(ld);
		ld = LocalDate.now().plusMonths(10);
		System.out.println(ld);
		ld = LocalDate.now().plusWeeks(1);
		System.out.println(ld);
		ld = LocalDate.now().plusYears(2);
		System.out.println(ld);

		ld = LocalDate.now();
		System.out.println(ld.toString());

		period = LocalDate.now().until(LocalDate.of(2025,10,10));
		System.out.println(period.getYears());
		
		ld = LocalDate.now();
		ld = ld.withDayOfMonth(2);
		System.out.println(ld);
		ld = LocalDate.now();
		ld = ld.withDayOfYear(3);
		System.out.println(ld);

		ld = ld.withMonth(2);
		System.out.println(ld);
		ld = ld.withYear(1988);
		System.out.println(ld);
	}
	
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

细水长流cpu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值