中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

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

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

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

一、舊時間日期問題

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

    • java.util.Date 類包含時間和日期

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

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

  3. 時間日期格式化類在 java.text 包下

  4. 時區(qū)處理困難,并不支持國際化,沒有時區(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è)計不合理Date date = new Date(2022, 7, 30);System.out.println(date); // Wed Aug 30 00:00:00 CST 3922System.out.println("--------------------");// 存在線程安全問題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();}}
}

二、新時間日期概述

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

  • 新時間日期 API 位于 java.time 包下

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

三、新時間日期操作

1、新時間日期創(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)建指定時間
LocalTime time1 = LocalTime.of(15, 30, 30, 123);
System.out.println(time1);
  • 創(chuàng)建當(dāng)前時間
LocalTime time2 = LocalTime.now();
System.out.println(time2);
  • 創(chuàng)建指定日期時間
LocalDateTime localDateTime1 = LocalDateTime.of(2022, 6, 30, 15, 30, 30, 123);
System.out.println(localDateTime1);
  • 創(chuàng)建當(dāng)前日期時間
LocalDateTime localDateTime2 = LocalDateTime.now();
System.out.println(localDateTime2);
2、新時間日期信息獲取
  • LocalDate 對象信息獲取
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 對象信息獲取
LocalTime localTime = LocalTime.now();System.out.println("時:" + localTime.getHour());
System.out.println("分:" + localTime.getMinute());
System.out.println("秒:" + localTime.getSecond());
System.out.println("納秒:" + localTime.getNano());
  • LocalDateTime 對象信息獲取
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("時:" + localDateTime.getHour());
System.out.println("分:" + localDateTime.getMinute());
System.out.println("秒:" + localDateTime.getSecond());
System.out.println("納秒" + localDateTime.getNano());
3、新時間日期修改
  • 通過設(shè)置時間日期進行修改
LocalDateTime now = LocalDateTime.now();System.out.println("當(dāng)前日期時間:" + now);
System.out.println("修改年:" + now.withYear(2000));
System.out.println("修改月:" + now.withMonth(10));
System.out.println("修改日:" + now.withDayOfMonth(25));
System.out.println("修改時:" + now.withHour(20));
System.out.println("修改分:" + now.withMinute(10));
System.out.println("修改秒:" + now.withSecond(30));
System.out.println("修改納秒:" + now.withNano(123456));
  • 通過加減時間日期進行修改
LocalDateTime now = LocalDateTime.now();System.out.println("五年后:" + now.plusYears(5));
System.out.println("五個月后:" + now.plusMonths(5));
System.out.println("五天后:" + now.plusDays(5));
System.out.println("五小時后:" + 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("五個月前:" + now.minusMonths(5));
System.out.println("五天前:" + now.minusDays(5));
System.out.println("五小時前:" + now.minusHours(5));
System.out.println("五分鐘前:" + now.minusMinutes(5));
System.out.println("五秒前:" + now.minusSeconds(5));
System.out.println("五納秒前:" + now.minusNanos(5));
4、新時間日期線程安全問題
  • 新時間日期類每次修改都會創(chuàng)建新的對象,原來的對象是不會被修改的,不會存在線程安去問題
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、新時間日期比較
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));}
}

四、新時間日期格式化與解析

  • 使用 java.time.format.DateTimeFormatter 進行格式化和解析操作
1、新時間日期格式化
  • 使用系統(tǒng)默認(rèn)格式進行格式化
LocalDateTime now = LocalDateTime.now();DateTimeFormatter basicIsoDate = DateTimeFormatter.BASIC_ISO_DATE;String format = now.format(basicIsoDate);
System.out.println(format);
  • 使用指定格式進行格式化
LocalDateTime now = LocalDateTime.now();DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");String format = now.format(dateTimeFormatter);
System.out.println(format);
2、新時間日期解析
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);}
}

五、時間戳

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

六、計算時間日期差

  • Duration 和 Period 類,用來計算時間日期差
1、計算時間差
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ù)差:" + duration.toHours());System.out.println("分鐘數(shù)差:" + duration.toMinutes());System.out.println("秒數(shù)差:" + duration.toMillis());System.out.println("納秒數(shù)差:" + duration.toNanos());}
}
2、計算日期差
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());}
}

七、時間矯正器

1、TemporalAdjuster
(1)基本介紹
  • TemporalAdjuster 是一個函數(shù)式接口,adjustInto 方法需要傳入一個 Temporal 接口,Temporal 接口的實現(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)整為下個月的第一天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 接口的實現(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);}
}

八、時區(qū)

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

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

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

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

相關(guān)文章:

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