内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

JDK8時(shí)間相關(guān)類超詳細(xì)總結(jié)2(含多個(gè)實(shí)例)-創(chuàng)新互聯(lián)

一、帶時(shí)區(qū)的時(shí)間 1.獲取當(dāng)前時(shí)間對象(帶時(shí)區(qū))
import java.time.ZonedDateTime;
public class demo1 {public static void main(String[] args) {
	    ZonedDateTime now = ZonedDateTime.now();
        System.out.println(now);
      
    }
}

2023-01-13T19:24:18.389+08:00[Asia/Shanghai]

創(chuàng)新互聯(lián)建站是一家網(wǎng)站設(shè)計(jì)公司,集創(chuàng)意、互聯(lián)網(wǎng)應(yīng)用、軟件技術(shù)為一體的創(chuàng)意網(wǎng)站建設(shè)服務(wù)商,主營產(chǎn)品:響應(yīng)式網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)、成都全網(wǎng)營銷推廣。我們專注企業(yè)品牌在網(wǎng)站中的整體樹立,網(wǎng)絡(luò)互動的體驗(yàn),以及在手機(jī)等移動端的優(yōu)質(zhì)呈現(xiàn)。做網(wǎng)站、網(wǎng)站設(shè)計(jì)、移動互聯(lián)產(chǎn)品、網(wǎng)絡(luò)運(yùn)營、VI設(shè)計(jì)、云產(chǎn)品.運(yùn)維為核心業(yè)務(wù)。為用戶提供一站式解決方案,我們深知市場的競爭激烈,認(rèn)真對待每位客戶,為客戶提供賞析悅目的作品,網(wǎng)站的價(jià)值服務(wù)。
2.獲取指定的時(shí)間對象(帶時(shí)區(qū))1/年月日時(shí)分秒納秒方式指定
import java.time.Instant;
public class demo1 {public static void main(String[] args) {
		ZonedDateTime time1 = ZonedDateTime.of(2023, 1, 1, 8, 30, 0, 0, ZoneId.of("Asia/Shanghai"));
        System.out.println(time1);
      
    }
}

2023-01-01T08:30+08:00[Asia/Shanghai]

3.通過Instant + 時(shí)區(qū)的方式指定獲取時(shí)間對象
import java.time.Instant;
public class demo1 {public static void main(String[] args) {Instant instant = Instant.ofEpochMilli(0L);
		ZoneId zoneId = ZoneId.of("Asia/Shanghai");
		ZonedDateTime time2 = ZonedDateTime.ofInstant(instant, zoneId);
		System.out.println(time2);
      
    }
}

1970-01-01T08:00+08:00[Asia/Shanghai]

4.修改時(shí)間
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class Demo8 {public static void main(String[] args) {Instant instant = Instant.ofEpochMilli(0L);
        ZoneId zoneId = ZoneId.of("Asia/Shanghai");
        ZonedDateTime time2 = ZonedDateTime.ofInstant(instant, zoneId);
        ZonedDateTime time3 = time2.withYear(2000);
        System.out.println(time3);

        ZonedDateTime time4 = time3.minusYears(1);
        System.out.println(time4);

        ZonedDateTime time5 = time4.plusYears(1);
        System.out.println(time5);
    }
}

2000-01-01T08:00+08:00[Asia/Shanghai]
1999-01-01T08:00+08:00[Asia/Shanghai]
2000-01-01T08:00+08:00[Asia/Shanghai]

二、DateTimeFormatter
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
//獲取時(shí)間對象
ZonedDateTime time = Instant.now().atZone(ZoneId.of("Asia/Shanghai"));

// 解析/格式化器
DateTimeFormatter dtf1=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm;ss EE a");
// 格式化
System.out.println(dtf1.format(time));

2023-01-14 23:55;55 星期六 下午

三、LocalDate 1. 獲取當(dāng)前時(shí)間的日歷對象(包含年月日)
//1.獲取當(dāng)前時(shí)間的日歷對象(包含 年月日)
LocalDate nowDate = LocalDate.now();
//System.out.println("今天的日期:" + nowDate);
2.獲取指定的時(shí)間的日歷對象
LocalDate ldDate = LocalDate.of(2023, 1, 1);
System.out.println("指定日期:" + ldDate);

System.out.println("=============================");

//3.get系列方法獲取日歷中的每一個(gè)屬性值//獲取年
int year = ldDate.getYear();
System.out.println("year: " + year);
//獲取月//方式一:
Month m = ldDate.getMonth();
System.out.println(m);
System.out.println(m.getValue());

//方式二:
int month = ldDate.getMonthValue();
System.out.println("month: " + month);


//獲取日
int day = ldDate.getDayOfMonth();
System.out.println("day:" + day);

//獲取一年的第幾天
int dayofYear = ldDate.getDayOfYear();
System.out.println("dayOfYear:" + dayofYear);

//獲取星期
DayOfWeek dayOfWeek = ldDate.getDayOfWeek();
System.out.println(dayOfWeek);
System.out.println(dayOfWeek.getValue());

//is開頭的方法表示判斷
System.out.println(ldDate.isBefore(ldDate));
System.out.println(ldDate.isAfter(ldDate));

//with開頭的方法表示修改,只能修改年月日
LocalDate withLocalDate = ldDate.withYear(2000);
System.out.println(withLocalDate);

//minus開頭的方法表示減少,只能減少年月日
LocalDate minusLocalDate = ldDate.minusYears(1);
System.out.println(minusLocalDate);

//plus開頭的方法表示增加,只能增加年月日
LocalDate plusLocalDate = ldDate.plusDays(1);
System.out.println(plusLocalDate);
四、LocalTime 1.獲取本地時(shí)間的日歷對象(包含時(shí)分秒)
LocalTime nowTime = LocalTime.now();
System.out.println("今天的時(shí)間:" + nowTime);

int hour = nowTime.getHour();//時(shí)
System.out.println("hour: " + hour);

int minute = nowTime.getMinute();//分
System.out.println("minute: " + minute);

int second = nowTime.getSecond();//秒
System.out.println("second:" + second);

int nano = nowTime.getNano();//納秒
System.out.println("nano:" + nano);
System.out.println("------------------------------------");
System.out.println(LocalTime.of(8, 20));//時(shí)分
System.out.println(LocalTime.of(8, 20, 30));//時(shí)分秒
System.out.println(LocalTime.of(8, 20, 30, 150));//時(shí)分秒納秒
LocalTime mTime = LocalTime.of(8, 20, 30, 150);
2.is系列的方法
System.out.println(nowTime.isBefore(mTime));
System.out.println(nowTime.isAfter(mTime));
3.with系列的方法

這個(gè)系列的方法有局限性,只能修改時(shí)、分、秒

System.out.println(nowTime.withHour(10));
4.plus系列的方法

這個(gè)系列的方法有局限性,只能修改時(shí)、分、秒

System.out.println(nowTime.plusHours(10));
五、LocalDateTime 1.當(dāng)前時(shí)間的的日歷對象(包含年月日時(shí)分秒)
LocalDateTime nowDateTime = LocalDateTime.now();

System.out.println("今天是:" + nowDateTime);//今天是:
System.out.println(nowDateTime.getYear());//年
System.out.println(nowDateTime.getMonthValue());//月
System.out.println(nowDateTime.getDayOfMonth());//日
System.out.println(nowDateTime.getHour());//時(shí)
System.out.println(nowDateTime.getMinute());//分
System.out.println(nowDateTime.getSecond());//秒
System.out.println(nowDateTime.getNano());//納秒
2.獲取日:當(dāng)年的第幾天
System.out.println("dayofYear:" + nowDateTime.getDayOfYear());
3.獲取星期
System.out.println(nowDateTime.getDayOfWeek());
System.out.println(nowDateTime.getDayOfWeek().getValue());
4.獲取月份
System.out.println(nowDateTime.getMonth());
System.out.println(nowDateTime.getMonth().getValue());

LocalDate ld = nowDateTime.toLocalDate();
System.out.println(ld);

LocalTime lt = nowDateTime.toLocalTime();
System.out.println(lt.getHour());
System.out.println(lt.getMinute());
System.out.println(lt.getSecond());
六、結(jié)語

還有一部分會在下一篇文章中講述

你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧

分享標(biāo)題:JDK8時(shí)間相關(guān)類超詳細(xì)總結(jié)2(含多個(gè)實(shí)例)-創(chuàng)新互聯(lián)
鏈接地址:http://www.rwnh.cn/article42/gdphc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站建站公司、網(wǎng)站改版品牌網(wǎng)站制作、外貿(mào)建站營銷型網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司
北流市| 美姑县| 景德镇市| 和田县| 丹东市| 常宁市| 嘉禾县| 胶南市| 万州区| 彰武县| 垦利县| 安乡县| 治多县| 濮阳市| 定陶县| 公主岭市| 乡宁县| 池州市| 银川市| 义马市| 松原市| 顺平县| 峨边| 阳新县| 大理市| 永兴县| 金山区| 东台市| 蕉岭县| 屏边| 徐汇区| 滨州市| 仁布县| 瑞昌市| 威宁| 涟水县| 花垣县| 皮山县| 白山市| 微山县| 本溪市|