国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁(yè) > news >正文

手機(jī)網(wǎng)站用什么域名盤多多搜索引擎入口

手機(jī)網(wǎng)站用什么域名,盤多多搜索引擎入口,有沒(méi)有免費(fèi)資源,做賣號(hào)網(wǎng)站嗎一、舊時(shí)間日期問(wèn)題 在 java.util 和 java.sql 包下都有時(shí)間日期類 java.util.Date 類包含時(shí)間和日期 java.sql.Date 類值包含日期 java.util.Date 類線程不安全,Date 對(duì)象可變 時(shí)間日期格式化類在 java.text 包下 時(shí)區(qū)處理困難,并不支持國(guó)際化&…

一、舊時(shí)間日期問(wèn)題

  1. 在 java.util 和 java.sql 包下都有時(shí)間日期類

    • java.util.Date 類包含時(shí)間和日期

    • java.sql.Date 類值包含日期

  2. java.util.Date 類線程不安全,Date 對(duì)象可變

  3. 時(shí)間日期格式化類在 java.text 包下

  4. 時(shí)區(qū)處理困難,并不支持國(guó)際化,沒(méi)有時(shí)區(qū)支持

package com.my.olddate;import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;public class OldDateTest {public static void main(String[] args) {// 設(shè)計(jì)不合理Date date = new Date(2022, 7, 30);System.out.println(date); // Wed Aug 30 00:00:00 CST 3922System.out.println("--------------------");// 存在線程安全問(wèn)題SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");for (int i = 0; i < 50; i++) {new Thread(() -> {try {System.out.println(simpleDateFormat.parse("2022-07-30"));} catch (ParseException e) {e.printStackTrace();}}).start();}}
}

二、新時(shí)間日期概述

1、基本介紹
  • JDK 8 增加了一套全新的時(shí)間日期 API,這套 API 設(shè)計(jì)合理,線程安全

  • 新時(shí)間日期 API 位于 java.time 包下

2、關(guān)鍵類介紹
說(shuō)明
LocalDate日期,年月日
LocalTime時(shí)間,時(shí)分秒
LocalDateTime日期時(shí)間,年月日時(shí)分秒
DateTimeFormatter日期時(shí)間格式化類
Instant時(shí)間戳,時(shí)間瞬間
Duration計(jì)算時(shí)間差
Period計(jì)算日期差
ZonedDateTime包含時(shí)區(qū)的時(shí)間
  • Java 中使用的是 ISO 8601 日期和時(shí)間的表示方法,是世界民用歷法,即公歷,平年有 365 天,閏年有 366 天

三、新時(shí)間日期操作

1、新時(shí)間日期創(chuàng)建
  • 創(chuàng)建指定日期
LocalDate date1 = LocalDate.of(2022, 6, 30);
System.out.println(date1);
  • 創(chuàng)建當(dāng)前日期
LocalDate date2 = LocalDate.now();
System.out.println(date2);
  • 創(chuàng)建指定時(shí)間
LocalTime time1 = LocalTime.of(15, 30, 30, 123);
System.out.println(time1);
  • 創(chuàng)建當(dāng)前時(shí)間
LocalTime time2 = LocalTime.now();
System.out.println(time2);
  • 創(chuàng)建指定日期時(shí)間
LocalDateTime localDateTime1 = LocalDateTime.of(2022, 6, 30, 15, 30, 30, 123);
System.out.println(localDateTime1);
  • 創(chuàng)建當(dāng)前日期時(shí)間
LocalDateTime localDateTime2 = LocalDateTime.now();
System.out.println(localDateTime2);
2、新時(shí)間日期信息獲取
  • LocalDate 對(duì)象信息獲取
LocalDate localDate = LocalDate.now();System.out.println("年:" + localDate.getDayOfYear());
System.out.println("月:" + localDate.getMonth().getValue() + "  " + localDate.getMonth());
System.out.println("日:" + localDate.getDayOfMonth());
System.out.println("星期:" + localDate.getDayOfWeek().getValue() + "  " + localDate.getDayOfWeek());
  • LocalTime 對(duì)象信息獲取
LocalTime localTime = LocalTime.now();System.out.println("時(shí):" + localTime.getHour());
System.out.println("分:" + localTime.getMinute());
System.out.println("秒:" + localTime.getSecond());
System.out.println("納秒:" + localTime.getNano());
  • LocalDateTime 對(duì)象信息獲取
LocalDateTime localDateTime = LocalDateTime.now();System.out.println("年:" + localDateTime.getDayOfYear());
System.out.println("月:" + localDateTime.getMonth().getValue() + "  " + localDateTime.getMonth());
System.out.println("日:" + localDateTime.getDayOfMonth());
System.out.println("星期:" + localDateTime.getDayOfWeek().getValue() + "  " + localDateTime.getDayOfWeek());
System.out.println("時(shí):" + localDateTime.getHour());
System.out.println("分:" + localDateTime.getMinute());
System.out.println("秒:" + localDateTime.getSecond());
System.out.println("納秒" + localDateTime.getNano());
3、新時(shí)間日期修改
  • 通過(guò)設(shè)置時(shí)間日期進(jìn)行修改
LocalDateTime now = LocalDateTime.now();System.out.println("當(dāng)前日期時(shí)間:" + now);
System.out.println("修改年:" + now.withYear(2000));
System.out.println("修改月:" + now.withMonth(10));
System.out.println("修改日:" + now.withDayOfMonth(25));
System.out.println("修改時(shí):" + now.withHour(20));
System.out.println("修改分:" + now.withMinute(10));
System.out.println("修改秒:" + now.withSecond(30));
System.out.println("修改納秒:" + now.withNano(123456));
  • 通過(guò)加減時(shí)間日期進(jìn)行修改
LocalDateTime now = LocalDateTime.now();System.out.println("五年后:" + now.plusYears(5));
System.out.println("五個(gè)月后:" + now.plusMonths(5));
System.out.println("五天后:" + now.plusDays(5));
System.out.println("五小時(shí)后:" + now.plusHours(5));
System.out.println("五分鐘后:" + now.plusMinutes(5));
System.out.println("五秒后:" + now.plusSeconds(5));
System.out.println("五納秒后:" + now.plusNanos(5));System.out.println("--------------------");System.out.println("五年前:" + now.minusYears(5));
System.out.println("五個(gè)月前:" + now.minusMonths(5));
System.out.println("五天前:" + now.minusDays(5));
System.out.println("五小時(shí)前:" + now.minusHours(5));
System.out.println("五分鐘前:" + now.minusMinutes(5));
System.out.println("五秒前:" + now.minusSeconds(5));
System.out.println("五納秒前:" + now.minusNanos(5));
4、新時(shí)間日期線程安全問(wèn)題
  • 新時(shí)間日期類每次修改都會(huì)創(chuàng)建新的對(duì)象,原來(lái)的對(duì)象是不會(huì)被修改的,不會(huì)存在線程安去問(wèn)題
package com.my.newdate;import java.time.LocalDateTime;public class NewDateSafeTest {public static void main(String[] args) {LocalDateTime now = LocalDateTime.now();LocalDateTime localDateTime = now.plusYears(5);System.out.println(now + "  " + now.hashCode());System.out.println(localDateTime + "  " + localDateTime.hashCode());}
}
5、新時(shí)間日期比較
package com.my.newdate;import java.time.LocalDateTime;public class NewDateCompareTest {public static void main(String[] args) {LocalDateTime now = LocalDateTime.now();LocalDateTime localDateTime = LocalDateTime.of(2020, 1, 1, 15, 30, 30);System.out.println(now.isAfter(localDateTime));System.out.println(now.isBefore(localDateTime));System.out.println(now.isEqual(localDateTime));}
}

四、新時(shí)間日期格式化與解析

  • 使用 java.time.format.DateTimeFormatter 進(jìn)行格式化和解析操作
1、新時(shí)間日期格式化
  • 使用系統(tǒng)默認(rèn)格式進(jìn)行格式化
LocalDateTime now = LocalDateTime.now();DateTimeFormatter basicIsoDate = DateTimeFormatter.BASIC_ISO_DATE;String format = now.format(basicIsoDate);
System.out.println(format);
  • 使用指定格式進(jìn)行格式化
LocalDateTime now = LocalDateTime.now();DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");String format = now.format(dateTimeFormatter);
System.out.println(format);
2、新時(shí)間日期解析
package com.my.newdate;import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;public class NewDateParseTest {public static void main(String[] args) {String str2 = "2022-07-30 17:36:44";DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");LocalDateTime localDateTime2 = LocalDateTime.parse(str2, dateTimeFormatter);System.out.println(localDateTime2);}
}

五、時(shí)間戳

1、基本介紹
  • Instant 類,時(shí)間戳,可以獲取從 1970-01-01 00:00:00 起的秒數(shù)
2、基本使用
  • 獲取時(shí)間戳
Instant now = Instant.now();
System.out.println(now);
  • 獲取秒數(shù)
Instant now = Instant.now();System.out.println(now.getEpochSecond());
  • 獲取納秒數(shù)
Instant now = Instant.now();System.out.println(now.toEpochMilli());
  • 通過(guò)秒數(shù)獲取時(shí)間戳
Instant instant = Instant.ofEpochSecond(1659176030L);
System.out.println(instant);
  • 通過(guò)納秒數(shù)獲取時(shí)間戳
Instant instant2 = Instant.ofEpochMilli(1659176030725L);
System.out.println(instant2);
  • 耗時(shí)統(tǒng)計(jì)
Instant start = Instant.now();
Thread.sleep(5);
Instant end = Instant.now();
System.out.println("耗時(shí)(納秒):" + (end.toEpochMilli() - start.toEpochMilli()));

六、計(jì)算時(shí)間日期差

  • Duration 和 Period 類,用來(lái)計(jì)算時(shí)間日期差
1、計(jì)算時(shí)間差
package com.my.newdate;import java.time.Duration;
import java.time.LocalTime;public class DurationTest {public static void main(String[] args) {LocalTime now = LocalTime.now();LocalTime time = LocalTime.of(10, 1, 1);Duration duration = Duration.between(time, now);System.out.println("天數(shù)差:" + duration.toDays());System.out.println("小時(shí)數(shù)差:" + duration.toHours());System.out.println("分鐘數(shù)差:" + duration.toMinutes());System.out.println("秒數(shù)差:" + duration.toMillis());System.out.println("納秒數(shù)差:" + duration.toNanos());}
}
2、計(jì)算日期差
package com.my.newdate;import java.time.LocalDate;
import java.time.Period;public class PeriodTest {public static void main(String[] args) {LocalDate now = LocalDate.now();LocalDate date = LocalDate.of(2020, 1, 1);Period period = Period.between(date, now);System.out.println("年份差:" + period.getYears());System.out.println("月份差:" + period.getMonths());System.out.println("日份差:" + period.getDays());}
}

七、時(shí)間矯正器

1、TemporalAdjuster
(1)基本介紹
  • TemporalAdjuster 是一個(gè)函數(shù)式接口,adjustInto 方法需要傳入一個(gè) Temporal 接口,Temporal 接口的實(shí)現(xiàn)類有LocalDate、LocalTime、LocalDateTime 等
@FunctionalInterface
public interface TemporalAdjuster {Temporal adjustInto(Temporal temporal);
}
(2)基本使用
package com.my.newdate;import java.time.LocalDateTime;
import java.time.temporal.TemporalAdjuster;public class TemporalAdjusterTest {public static void main(String[] args) {// 將當(dāng)前日期調(diào)整為下個(gè)月的第一天LocalDateTime now = LocalDateTime.now();TemporalAdjuster temporalAdjuster = (temporal) -> {LocalDateTime localDateTime = (LocalDateTime) temporal;LocalDateTime nextLocalDateTime = localDateTime.plusMonths(1).withDayOfMonth(1);return nextLocalDateTime;};LocalDateTime nextLocalDateTime = now.with(temporalAdjuster);System.out.println(nextLocalDateTime);}
}
2、TemporalAdjusters
(1)基本介紹
  • TemporalAdjusterTests 類有大量靜態(tài)方法提供 TemporalAdjusterTest 接口的實(shí)現(xiàn)
(2)基本使用
package com.my.newdate;import java.time.LocalDateTime;
import java.time.temporal.TemporalAdjusters;public class TemporalAdjustersTest {public static void main(String[] args) {// 將當(dāng)前日期調(diào)整為明年的第一天LocalDateTime now = LocalDateTime.now();LocalDateTime nextLocalDateTime = now.with(TemporalAdjusters.firstDayOfNextYear());System.out.println(nextLocalDateTime);}
}

八、時(shí)區(qū)

1、基本介紹
  • JDK 8 增加了對(duì)時(shí)區(qū)的支持

  • LocalDate、LocalTime 和 LocalDateTime 類是不支持時(shí)區(qū)的

  • 支持時(shí)區(qū)類:ZonedDate、ZonedTime 和 ZonedDateTime 類

2、基本使用
  • 獲取所有時(shí)區(qū) ID
ZoneId.getAvailableZoneIds().forEach(System.out::println);
  • 獲取標(biāo)準(zhǔn)時(shí)間,對(duì)比當(dāng)前時(shí)間,我國(guó)使用東八區(qū),比標(biāo)準(zhǔn)時(shí)間早 8 個(gè)小時(shí)
// 獲取當(dāng)前時(shí)間
LocalDateTime now = LocalDateTime.now();
System.out.println(now);// 獲取標(biāo)準(zhǔn)時(shí)間
ZonedDateTime zonedDateTime = ZonedDateTime.now(Clock.systemUTC());
System.out.println(zonedDateTime);
  • 使用計(jì)算機(jī)默認(rèn)時(shí)區(qū),獲取當(dāng)前時(shí)間
ZonedDateTime zonedDateTime = ZonedDateTime.now();
System.out.println(zonedDateTime);
  • 獲取指定時(shí)區(qū)的時(shí)間
ZonedDateTime zonedDateTime2 = ZonedDateTime.now(ZoneId.of("America/Bogota"));
System.out.println(zonedDateTime2);
http://aloenet.com.cn/news/44411.html

相關(guān)文章:

  • 網(wǎng)站開(kāi)發(fā)文件綜述網(wǎng)絡(luò)營(yíng)銷企業(yè)網(wǎng)站
  • 軟件開(kāi)發(fā)需要多久網(wǎng)站優(yōu)化有哪些技巧
  • 大良網(wǎng)站制作福建seo外包
  • 聊城網(wǎng)站建設(shè)泉州seo優(yōu)化
  • 如何免費(fèi)建一個(gè)wordpressseo文章生成器
  • 在線做熱圖的網(wǎng)站站長(zhǎng)工具seo綜合查詢5g
  • 深一集團(tuán)的網(wǎng)站誰(shuí)做的360開(kāi)戶推廣
  • 武漢哪家網(wǎng)站建設(shè)公司好怎么用手機(jī)創(chuàng)建網(wǎng)站
  • 萍鄉(xiāng)做網(wǎng)站的百度云網(wǎng)盤資源搜索引擎入口
  • 卡姐的wap是什么意思百度seo站長(zhǎng)工具
  • 網(wǎng)站怎么做搜索引擎才能收錄百度指數(shù)有什么參考意義
  • 做照片書(shū)的模板下載網(wǎng)站好惠州網(wǎng)站推廣排名
  • 沈陽(yáng)網(wǎng)站建設(shè)專家seo營(yíng)銷方案
  • 建站免費(fèi)加盟網(wǎng)絡(luò)營(yíng)銷推廣的優(yōu)勢(shì)
  • 有哪些做普洱茶網(wǎng)站的女生讀網(wǎng)絡(luò)營(yíng)銷與電商直播
  • 廣州開(kāi)發(fā)區(qū)醫(yī)院南崗院區(qū)莆田seo推廣公司
  • app開(kāi)發(fā)公司收費(fèi)seo優(yōu)化包括哪些
  • 哪個(gè)公司網(wǎng)站做的好網(wǎng)站推廣的目的是什么
  • 沈陽(yáng)犀牛云做網(wǎng)站怎么樣長(zhǎng)沙正規(guī)seo優(yōu)化價(jià)格
  • 杭州 手機(jī)網(wǎng)站免費(fèi)搭建網(wǎng)站的軟件
  • 使用tag的網(wǎng)站最近一周的新聞大事10條
  • 織夢(mèng)學(xué)校網(wǎng)站seo關(guān)鍵詞推廣方式
  • 百度搜索推廣技巧免費(fèi)外鏈網(wǎng)站seo發(fā)布
  • 沈陽(yáng)做網(wǎng)站哪家便宜深圳最新消息今天
  • 做的好的國(guó)外網(wǎng)站東莞做好網(wǎng)絡(luò)推廣
  • 貿(mào)易公司寮步網(wǎng)站建設(shè)極致發(fā)燒百度在線入口
  • 赤峰做企業(yè)網(wǎng)站公司企業(yè)網(wǎng)站建設(shè)方案策劃
  • 網(wǎng)站彈出信息怎么做怎么快速優(yōu)化關(guān)鍵詞排名
  • 專門做娛樂(lè)場(chǎng)所的設(shè)計(jì)網(wǎng)站近三天發(fā)生的大事
  • 可以做動(dòng)效的網(wǎng)站百度競(jìng)價(jià)代運(yùn)營(yíng)外包