Joda Time出現(xiàn)的背景
在java1.0中骤公,對(duì)日期和時(shí)間的支持只能依賴(lài)java.util.Date類(lèi)霎俩。正如類(lèi)名所表達(dá)的,這個(gè)類(lèi)無(wú)法表示日期墨吓,只能以毫秒的精度表示時(shí)間。更糟糕的是它的易用性纹磺,由于某些未知的設(shè)計(jì)決策帖烘,這個(gè)類(lèi)的易用性被深深的損害了,比如:年份的起始日期選擇是1990年爽航,月份的起始從0開(kāi)始蚓让。在java1.1中,Date類(lèi)中的很多方法被廢棄了讥珍,取而代之的是java.util.Calendar類(lèi)历极。Calendar類(lèi)也有類(lèi)似的問(wèn)題和設(shè)計(jì)缺陷,導(dǎo)致使用這些方法寫(xiě)出的代碼非常容易出錯(cuò)衷佃。比如月份依舊是從0開(kāi)始計(jì)算(拿掉了由1990年開(kāi)始計(jì)算年份這一設(shè)計(jì))趟卸。更糟的是,有的特性只在某一個(gè)類(lèi)有提供氏义,比如用于語(yǔ)言無(wú)關(guān)方式格式化和解析日期或時(shí)間的DateFormat方法就只在Date類(lèi)有锄列。
DateFormat不是線程安全的,二個(gè)線程同時(shí)使用formatter解析日期惯悠,你可能會(huì)得到無(wú)法預(yù)期的結(jié)果邻邮。
在jdk1.8之前,這些問(wèn)題使得用戶們使用了第三方日期和時(shí)間庫(kù)克婶,比如Joda Time筒严。jdk1.8大量借鑒了Joda Time特任。
Joda Time項(xiàng)目
Java SE 8之前的標(biāo)準(zhǔn)日期和時(shí)間類(lèi)很差情萤。 通過(guò)解決這個(gè)問(wèn)題鸭蛙,Joda-Time在Java SE 8之前成為Java的實(shí)際標(biāo)準(zhǔn)日期和時(shí)間庫(kù)。請(qǐng)注意筋岛,從Java SE 8起娶视,用戶被要求遷移到j(luò)ava.time(JSR-310) - JDK的核心部分,取代了這個(gè)項(xiàng)目睁宰。如果我們工作中的jdk版本是1.8版本之前可以使用Joda Time項(xiàng)目肪获,Joda項(xiàng)目中其實(shí)包括的不止Joda Time寝凌,還包括Joda-Money ,Joda-Beans孝赫,Joda-Convert 硫兰,Joda-Collect,Joda Primitives項(xiàng)目寒锚,有興趣可以在Joda官網(wǎng)地址中了解一下劫映。
pom依賴(lài):
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.9</version>
</dependency>
第一個(gè)demo
package com.zhihao.joda;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
public class JodaTest2 {
public static void main(String[] args) {
DateTime today = new DateTime();
DateTime datetorrow = today.plusDays(1);
System.out.println(today.toString("yyyy-MM-dd"));//2017-06-26
System.out.println(today.toString("yyyy-MM-dd HH:mm:ss"));//2017-06-26 22:04:03
System.out.println(datetorrow.toString("yyyy-MM-dd"));//2017-06-27
System.out.println("......................");
//獲得一個(gè)時(shí)間的副本,將day設(shè)置成自己制定的時(shí)間,不改變?cè)路萆睬埃桓淖內(nèi)掌? DateTime d1 = today.withDayOfMonth(1);
System.out.println(d1.toString("yyyy-MM-dd"));//2017-06-01
System.out.println("......................");
LocalDate localDate = new LocalDate();
System.out.println(localDate);//2017-06-26
System.out.println("........................");
//獲取當(dāng)前時(shí)間三個(gè)月后的月份的最后一天
localDate = localDate.plusMonths(3).dayOfMonth().withMaximumValue();
System.out.println(localDate);//2017-09-30
System.out.println("........................");
//計(jì)算二年前第三個(gè)月最后一天的日期
DateTime dateTime = new DateTime();
DateTime dateTime2 = dateTime.minusYears(2).monthOfYear().setCopy(3).
dayOfMonth().withMinimumValue();
System.out.println(dateTime2.toString("yyyy-MM-dd"));//2017-09-30
}
}
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import java.util.Date;
public class JodaTest3 {
//將utc時(shí)間轉(zhuǎn)換成java中的Date格式
public static Date convertUTC2Date(String utcDate){
try{
DateTime dateTime =DateTime.parse(utcDate, DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
return dateTime.toDate();
}catch (Exception ex){
return null;
}
}
//將java中的date格式的時(shí)間轉(zhuǎn)換成utc時(shí)間標(biāo)準(zhǔn)
public static String ConvertDate2UTC(Date javaDate){
DateTime dateTime = new DateTime(javaDate, DateTimeZone.UTC);
return dateTime.toString();
}
//將Date類(lèi)型轉(zhuǎn)換成字符串
public static String convertDate2LocalByDateformat(Date javaDate,String dateFormat){
DateTime dateTime = new DateTime(javaDate);
return dateTime.toString(dateFormat);
}
public static void main(String[] args) {
System.out.println(JodaTest3.convertUTC2Date("2010-12-1T11:22:33.567Z"));//Wed Dec 01 19:22:33 CST 2010
System.out.println(JodaTest3.ConvertDate2UTC(new Date()));//2017-06-26T14:09:53.606Z
System.out.println(JodaTest3.convertDate2LocalByDateformat(new Date(),"yyyy-MM-dd HH:mm:ss"));//2017-06-26 22:09:53
}
}
什么是UTC時(shí)間泳赋?
沒(méi)有時(shí)區(qū)概念,比如utc時(shí)間 為2010-12-1T11:22:33.567Z喇喉,如果是表示時(shí)區(qū)概念一般2010-12-1T11:22:33.567+08:00
關(guān)于Joda Time其他的日期和時(shí)間api可以看其依賴(lài)包下的具體類(lèi)祖今,具體使用方式也很簡(jiǎn)單看齊javadoc即可。
java8時(shí)間api
LocalDate拣技,LocalTime
LocalDate類(lèi)的實(shí)例是一個(gè)不可變的對(duì)象千诬,只提供了簡(jiǎn)單的日期,并不包含當(dāng)前的時(shí)間信息(只關(guān)注與年月日)膏斤。也不附帶任何與時(shí)區(qū)相關(guān)的信息徐绑。
LocalTime類(lèi)關(guān)注時(shí)分秒。
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.MonthDay;
public class Java8TimeTest {
public static void main(String[] args) {
//關(guān)注與年月日
LocalDate localDate = LocalDate.now();
System.out.println(localDate); //2017-06-26
System.out.println(localDate.getYear()); //2017莫辨,年
System.out.println(localDate.getMonthValue()); //6傲茄,月
System.out.println(localDate.getDayOfMonth()); //26,日
System.out.println(localDate.getDayOfWeek()); //MONDAY,星期幾
System.out.println(localDate.lengthOfMonth()); //30,返回當(dāng)前月份的長(zhǎng)度
System.out.println(localDate.isLeapYear());//false,是否是閏年
System.out.println("------------------");
LocalDate localDate2 = LocalDate.of(2017,4,1);
System.out.println(localDate2); //2017-04-01
System.out.println("------------------");
//MonthDay關(guān)注月份和日
LocalDate localDate3 = LocalDate.of(2017,3,25);
MonthDay monthDay = MonthDay.of(localDate3.getMonth(),localDate3.getDayOfMonth());
System.out.println(monthDay); //--03-25
MonthDay monthDay2 = MonthDay.from(LocalDate.of(2014,3,25));
System.out.println(monthDay2); //--03-25
if(monthDay.equals(monthDay2)){
System.out.println("equal");
}else{
System.out.println("not equal");
}
//關(guān)注與時(shí)分秒
LocalTime time = LocalTime.now();
System.out.println(time); //22:30:01.512
System.out.println(time.getHour()); //22,時(shí)
System.out.println(time.getMinute()); //30沮榜,分
System.out.println(time.getSecond()); //01盘榨,秒
LocalTime time2 = time.plusHours(3).plusMinutes(40);
System.out.println(time2); //02:10:01.512
}
}
package com.zhihao.date;
import java.time.LocalDate;
public class Java8TimeTest1 {
public static void main(String[] args) {
//LocalDate的parse只能轉(zhuǎn)換2007-12-03這樣的格式的,不能解析的也會(huì)拋出一個(gè)RuntimeException
//或者DateTimeParseException
LocalDate date = LocalDate.parse("2014-03-18");
LocalDate date2 = LocalDate.parse("2017-03-18");
System.out.println(date);
System.out.println(date2);
LocalDate nowdate = LocalDate.now();
String date3 = nowdate.toString();
System.out.println(date3); //2017-06-26
}
}
import java.time.*;
import java.time.temporal.ChronoUnit;
public class Java8TimeTest2 {
public static void main(String[] args) {
LocalDate localDate = LocalDate.now();
System.out.println(localDate); //2017-06-27
//當(dāng)前日期的二周后
LocalDate localDate2 = localDate.plus(2, ChronoUnit.WEEKS);
System.out.println(localDate2); //2017-07-11
System.out.println("............");
//當(dāng)前時(shí)間的二個(gè)月之前
LocalDate localDate3 = localDate.minus(2,ChronoUnit.MONTHS);
System.out.println(localDate3);//2017-04-27
System.out.println("..............");
Clock clock = Clock.systemDefaultZone(); //當(dāng)前時(shí)區(qū)的時(shí)刻
System.out.println(clock.millis()); //獲得當(dāng)前的毫秒數(shù),1498529786982
LocalDate localDate5 = LocalDate.now();
LocalDate localDate6 = LocalDate.of(2017,4,12);
System.out.println(localDate5.isBefore(localDate6)); //判斷時(shí)間在什么時(shí)間之前
System.out.println(localDate5.isAfter(localDate6)); //判斷時(shí)間在什么時(shí)間之后
System.out.println(localDate5.isEqual(localDate6)); //判斷時(shí)間和什么時(shí)間相等
System.out.println("..............");
}
}
LocalDateTime
一個(gè)沒(méi)有時(shí)區(qū)概念的日期-時(shí)間類(lèi)在ISO-8601 日期系統(tǒng)中,比如2007-12-03T10:15:30
package com.zhihao.date;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;
public class Java8TimeTest11 {
public static void main(String[] args) {
LocalDateTime dt1 = LocalDateTime.of(2017, Month.APRIL,18,13,45,20);
System.out.println(dt1);
LocalDate date1 = dt1.toLocalDate(); //通過(guò)LocalDateTime獲得LocalDate
LocalTime time1 = dt1.toLocalTime(); //通過(guò)LocalDateTime獲得LocalTime
System.out.println("date1======="+date1+"time1===="+time1);
LocalDate date = LocalDate.of(2014,02,26);
LocalTime time = LocalTime.of(12,23,20);
LocalDateTime dt2 = LocalDateTime.of(date,time);
System.out.println(dt2);
//LocalDate結(jié)合LocalTime成一個(gè)LocalDateTime
LocalDateTime dt3 = date.atTime(13,45,20);
System.out.println(dt3); //2014-02-26T13:45:20
//LocalDate結(jié)合LocalTime成一個(gè)LocalDateTime
LocalDateTime dt4 = date.atTime(time);
System.out.println(dt4); //2014-02-26T12:23:20
//LocalTime結(jié)合LocalDate成LocalDateTime
LocalDateTime dt5 = time.atDate(date);
System.out.println(dt5); //2014-02-26T12:23:20
}
}
機(jī)器的日期和時(shí)間格式
作為人蟆融,我們習(xí)慣與以星期幾草巡,幾號(hào),幾點(diǎn)型酥,幾分這樣的方式理解日期和時(shí)間山憨。對(duì)于計(jì)算機(jī)來(lái)說(shuō),建模時(shí)間最自然的格式是表示一個(gè)持續(xù)時(shí)間段上某個(gè)點(diǎn)的單一大整型數(shù)冕末。這也是新的java.time.Instant
類(lèi)對(duì)時(shí)間建模的方式萍歉,基本上它是以Unix元年時(shí)間(傳統(tǒng)的設(shè)定為UTC時(shí)區(qū)1970年1月1日午夜時(shí)分)開(kāi)始經(jīng)歷的秒數(shù)進(jìn)行計(jì)算侣颂。
package com.zhihao.date;
import java.time.Instant;
public class InstantTest {
public static void main(String[] args) {
Instant instant1 = Instant.ofEpochSecond(3);
System.out.println(instant1);//1970-01-01T00:00:03Z
//第一個(gè)參數(shù)是秒档桃,第二個(gè)是納秒?yún)?shù),納秒的存儲(chǔ)范圍是0至999,999,999
Instant instant2 = Instant.ofEpochSecond(3,0);
System.out.println(instant2);//1970-01-01T00:00:03Z
//2s之后的在加上100萬(wàn)納秒(1s)
Instant instant3 = Instant.ofEpochSecond(2,1000000000);
System.out.println(instant3); //1970-01-01T00:00:03Z
Instant instant4 = Instant.ofEpochSecond(4,-1000000000);
System.out.println(instant4); //1970-01-01T00:00:03Z
Instant instant = Instant.now();
System.out.println(instant);
}
}
Duration與Period
package com.zhihao.date;
import java.time.*;
public class DurationTest {
public static void main(String[] args) {
LocalTime time1 = LocalTime.of(18,23,45);
LocalTime time2 = LocalTime.of(23,34,56);
Duration d1 = Duration.between(time1,time2);
System.out.println(d1.getSeconds()); //18671
LocalDateTime localDateTime1 = LocalDateTime.of(2016,Month.MAY,12,11,13,11);
LocalDateTime localDateTime2 = LocalDateTime.of(2017, Month.AUGUST,18,23,45,20);
Duration d2 = Duration.between(localDateTime1,localDateTime2);
System.out.println(d2.getSeconds()); //40048329
Instant instant1 = Instant.ofEpochSecond(3);
Instant instant2 = Instant.ofEpochSecond(6);
Duration d3 = Duration.between(instant1,instant2);
System.out.println(d3.getSeconds()); //3
}
}
以年憔晒,月藻肄,日方式建模蔑舞,可以使用Period類(lèi)。
import java.time.Instant;
import java.time.LocalDate;
import java.time.Period;
public class Java8TimeTest4 {
public static void main(String[] args) {
//LocalDate localDate1 = LocalDate.now();
LocalDate localDate1 = LocalDate.of(2017,4,12);
LocalDate localDate2 = LocalDate.of(2018,3,16);
Period period = Period.between(localDate1,localDate2);
System.out.println(period.getYears()); //獲取相隔的年份差 0
System.out.println(period.getMonths()); //獲取相隔的月份差 11
System.out.println(period.getDays()); //獲取相隔的日子差 4
System.out.println("...............");
System.out.println(Instant.now()); //表示當(dāng)前的不帶時(shí)區(qū)的UTC標(biāo)準(zhǔn)時(shí)間,2017-04-12T14:40:29.309Z
}
}
關(guān)于二者其他的api可以對(duì)照java api文檔進(jìn)行查看嘹屯,比較淺顯攻询。
ZoneId和ZonedDateTime
新的java.time.ZoneId
替代了老版本的java.util.TimeZone
.
package com.zhihao.date;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Set;
import java.util.TreeSet;
public class Java8TimeTest3 {
public static void main(String[] args) {
//時(shí)區(qū)
Set<String> sets = ZoneId.getAvailableZoneIds();
//sets.stream().forEach(System.out::println);
//構(gòu)建一個(gè)TreeSet的匿名內(nèi)部類(lèi),然后里面是個(gè)代碼塊表示在實(shí)例創(chuàng)建的時(shí)候執(zhí)行這個(gè)代碼塊
TreeSet<String> treeSet = new TreeSet<String>(){
{
addAll(sets);
}
};
treeSet.stream().forEach(System.out::println);
System.out.println("........................");
ZoneId zoneId = ZoneId.of("Asia/Shanghai");
LocalDateTime localDateTime = LocalDateTime.now();
System.out.println(localDateTime);//2017-04-12T22:05:22.500
ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime,zoneId);
System.out.println(zonedDateTime); //2017-04-12T22:05:22.500+08:00[Asia/Shanghai]
System.out.println("..................");
YearMonth yearMonth = YearMonth.now();
System.out.println(yearMonth); //2017-06
System.out.println(yearMonth.lengthOfMonth()); //當(dāng)月有多少天,30
System.out.println(yearMonth.isLeapYear()); //是否是閏年,false
System.out.println(".............");
YearMonth yearMonth2 = YearMonth.of(2016,2);
System.out.println(yearMonth2); //2016-02
System.out.println(yearMonth2.lengthOfMonth()); //當(dāng)前的月有多少天,29
System.out.println(yearMonth2.lengthOfYear()); //一年有多少天,366
System.out.println(yearMonth2.isLeapYear()); //是否是閏年,true
}
}
package com.zhihao.date;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
public class ZoneOffsetTest {
public static void main(String[] args) {
ZoneOffset zoneOffset = ZoneOffset.of("-05:00");
LocalDateTime dateTime = LocalDateTime.of(2014, Month.MARCH,18,13,45);
OffsetDateTime offsetDateTime = OffsetDateTime.of(dateTime,zoneOffset);
System.out.println(offsetDateTime); //2014-03-18T13:45-05:00
}
}
java8還提供了一些別的日歷系統(tǒng),這些日歷系統(tǒng)中的每一個(gè)都有一個(gè)ThaiBuddhistDate州弟,MinguoDate钧栖,JapaneseDate對(duì)應(yīng)的日志類(lèi)。這邊不做介紹婆翔。
格式化與解析時(shí)間對(duì)象DateTimeFormatter
創(chuàng)建格式器最簡(jiǎn)單的方法是通過(guò)DateTimeFormatter的靜態(tài)工廠方法以及常量拯杠。像BASIC_ISO_DATE 和ISO_LOCAL_DATE這 樣 的 常 量 是DateTimeFormatter類(lèi) 的 預(yù) 定 義 實(shí) 例 。 所 有 的 DateTimeFormatter實(shí)例都能用于以一定的格式創(chuàng)建代表特定日期或時(shí)間的字符串啃奴。
和老的java.util.DateFormat相比較潭陪,所有的DateTimeFormatter實(shí)例都是線程安全的。所以最蕾,你能夠以單例模式創(chuàng)建格式器實(shí)例依溯,就像DateTimeFormatter所定義的那些常量,并能在多個(gè)線程間共享這些實(shí)例瘟则。DateTimeFormatter類(lèi)還支持一個(gè)靜態(tài)工廠方法黎炉,它可以按照某個(gè)特定的模式創(chuàng)建格式器.
package com.zhihao.date;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
public class DateUtil {
public static void main(String[] args) {
Date date = new Date();
Instant instant = date.toInstant();
ZoneId zone = ZoneId.systemDefault();
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone);
DateTimeFormatter formatter =DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formatdate = localDateTime.format(formatter);
System.out.println(formatdate);
System.out.println("...........");
LocalDate localDate = LocalDate.of(2017,3,17);
//BASIC_ISO_DATE格式,20111203
String str = localDate.format(DateTimeFormatter.BASIC_ISO_DATE);
System.out.println(str);
//DateTimeFormatter.ISO_LOCAL_DATE 格式 2017-03-17
String str2 = localDate.format(DateTimeFormatter.ISO_LOCAL_DATE);
System.out.println(str2);
//定義
String str3 = localDate.format(DateTimeFormatter.ofPattern("yyyy/MM/dd"));
System.out.println(str3);
LocalDate localDate1 = LocalDate.parse("20111203",DateTimeFormatter.BASIC_ISO_DATE);
System.out.println(localDate1); //2011-12-03
LocalDate localDate2 = LocalDate.parse("2017-03-17",DateTimeFormatter.ISO_LOCAL_DATE);
System.out.println(localDate2); //2017-03-17
}
}
使用TemporalAdjuster類(lèi)更精確的操縱日期
使用TemporalAdjuster類(lèi)更精確的操縱日期醋拧,不在局限于一次只能改變它的一個(gè)只拜隧,并且你還可以按照需求定義自己的日期轉(zhuǎn)換器。
TemporalAdjusters工廠類(lèi)為我們提供了很多便捷的操作趁仙。
package com.zhihao.date;
import java.time.DayOfWeek;
import java.time.LocalDate;
import static java.time.temporal.TemporalAdjusters.*;
public class TemporalAdjusterTest {
public static void main(String[] args) {
LocalDate localDate = LocalDate.of(2017,6,20);
System.out.println(localDate); //2017-06-20
//下一周的星期天
LocalDate newdata = localDate.with(nextOrSame(DayOfWeek.SUNDAY));
System.out.println(newdata); //2017-06-25
LocalDate lastDate = localDate.with(lastDayOfMonth());
System.out.println(lastDate); //2017-06-30
//表示當(dāng)前月的第二周的星期天
LocalDate date1 = localDate.with(dayOfWeekInMonth(2,DayOfWeek.SUNDAY));
System.out.println(date1); //2017-06-11
//當(dāng)前月的第一天
LocalDate date2 = localDate.with(firstDayOfMonth());
System.out.println(date2);
//下個(gè)月的第一天
LocalDate date3 = localDate.with(firstDayOfNextMonth());
System.out.println(date3); //2017-07-01
//明年的第一天
LocalDate date4 = localDate.with(firstDayOfNextYear());
System.out.println(date4); //2018-01-01
//當(dāng)前的以一天
LocalDate date5 = localDate.with(firstDayOfYear());
System.out.println(date5); //2017-01-01
//本月第一個(gè)滿足星期三的日期
LocalDate date6 =localDate.with(firstInMonth(DayOfWeek.WEDNESDAY));
System.out.println(date6); //2017-06-07
//今年的最后一天
LocalDate date7 = localDate.with(lastDayOfYear());
System.out.println(date7); //2017-12-31
//當(dāng)月最后一個(gè)滿足是星期四的日期
LocalDate date8 = localDate.with(lastInMonth(DayOfWeek.TUESDAY));
System.out.println(date8); //2017-06-30
//下個(gè)星期天的日期
LocalDate date9 = localDate.with(next(DayOfWeek.SUNDAY));
System.out.println(date9); //2017-06-25
System.out.println("localDate======="+localDate); //localDate=======2017-06-20
LocalDate localDate2 = LocalDate.of(2017,6,20);
LocalDate date13 = localDate2.with(nextOrSame(DayOfWeek.SUNDAY));
System.out.println(date13);
System.out.println("localDate2==="+localDate2);
//上個(gè)星期天的日期
LocalDate date10 = localDate.with(previous(DayOfWeek.SUNDAY));
System.out.println(date10); //2017-06-18
LocalDate date11 = localDate.with(previousOrSame(DayOfWeek.SUNDAY));
System.out.println(date11); //2017-06-18
LocalDate localDate1 = LocalDate.of(2017,6,7); //為本月第一個(gè)星期三
LocalDate date12 = localDate1.with(previousOrSame(DayOfWeek.WEDNESDAY));
System.out.println(date12); //2017-06-07
}
}
next/previous 創(chuàng)建一個(gè)新的日期洪添,并將其值設(shè)定為日期調(diào)整后或者調(diào)整前,第一個(gè)符合指定星 期幾要求的日期雀费。
nextOrSame/previousOrSame 創(chuàng)建一個(gè)新的日期干奢,并將其值設(shè)定為日期調(diào)整后或者調(diào)整前,第一個(gè)符合指定星 期幾要求的日期盏袄,如果該日期已經(jīng)符合要求忿峻,直接返回該對(duì)象。
總結(jié)
java8提供的日期-時(shí)間對(duì)象是不可變的辕羽。操作的結(jié)果總是返回一個(gè)新的實(shí)列逛尚,老的日期時(shí)間對(duì)象不會(huì)發(fā)生改變。所以提供的這些類(lèi)都很簡(jiǎn)單刁愿,但是需要我們多去使用它绰寞。