localdatetime now = localdatetime.
now();
//獲取當前日期
system.out.
println
("now = "
+ now)
;//now = 2020-01-27t22:23:33.320
system.out.
println
("now.getyear() = "
+ now.
getyear()
); = 2019
//注意獲取月份的兩個方法的區別
system.out.
println
("now.getmonth() = "
+ now.
getmonth()
); = january
system.out.
println
("now.getmonthvalue() = "
+ now.
getmonthvalue()
); = 1
system.out.
println
("now.getdayofmonth() = "
+ now.
getdayofmonth()
); = 27
system.out.
println
("now.gethour() = "
+ now.
gethour()
);system.out.
println
("now.getminute() = "
+ now.
getminute()
);system.out.
println
("now.getsecond() = "
+ now.
getsecond()
);//構造指定日期,eg.2020-08-08
localdatetime diydate = localdatetime.of(
2020,8
,8,0
,0,0
);system.out.
println
("diydate = "
+ diydate)
;//diydate = 2020-08-08t00:00
//修改日期
//①增加/減少幾個月
localdatetime localdatetime = localdatetime.
now();
system.out.
println
("localdatetime = "
+ localdatetime)
;//localdatetime = 2020-01-27t22:37:05.546
//下個月,plusmonth()
localdatetime = localdatetime.
plusmonths(1
);system.out.
println
("localdatetime = "
+ localdatetime)
;//localdatetime = 2020-02-27t22:37:05.546
//上個月,-1
localdatetime = localdatetime.
minusmonths(1
);//或者使用 plusmonth(-1)
//localdatetime = localdatetime.plusmonths(-1);
system.out.
println
("localdatetime = "
+ localdatetime)
;//localdatetime = 2020-01-27t22:37:05.546
//②修改到指定日期
localdatetime = localdatetime.
withyear
(2200);
system.out.
println
("localdatetime = "
+ localdatetime)
;//localdatetime = 2200-01-27t22:43:26.722
//格式化日期
//①自定義日期格式
string diyformatdate = now.
format
(datetimeformatter.
ofpattern
("yyyy-mm-dd hh:mm:ss"))
; system.out.
println
("diyformatdate = "
+ diyformatdate)
;//formatdate = 2020-01-27 22:47:21
//②幾種基本格式
string format = now.
format
(datetimeformatter.iso_date)
; system.out.
println
("format = "
+ format)
;//format = 2020-01-27
format = now.
format
(datetimeformatter.basic_iso_date)
; system.out.
println
("format = "
+ format)
;//format = 20200127
//解析日期
localdatetime parse = localdatetime.
parse
("2020-01-27 22:47:21"
, datetimeformatter.
ofpattern
("yyyy-mm-dd hh:mm:ss"))
; system.out.
println
("parse = "
+ parse)
;//parse = 2020-01-27t22:47:21
JDK 8 新特性 Stream map 相關
和 clojure 裡面的 map 理解 是一樣的,可以分別獲取流中的每乙個元素,然後在對其做一些操作 1.遍歷字串集合然後轉換成大寫字母 public static void main string args system.out.println newnames stream map 方式 ne...
jdk8學習總結
今天抽點時間對jdk8寫個總體的學習總結,一來當作乙個覆盤加深理解,二來也希望能夠對閱讀的朋友們有一點點幫助,同時也希望大家對文中不準確的內容予以指出。1 函式式介面與lambda表示式 首先說一下函式式介面的概念 介面中的抽象方法如果是重寫了object類的方法的話,是不參與計數的 另外如果乙個介...
JDK8中新的日期類學習
1 獲得當前日期 年 月 日 localdate localdate localdate.now system.out.println localdate 返回的是個列舉物件 system.out.println 年 localdate.getyear t月 localdate.getmonth g...