黄色网址大全免费-黄色网址你懂得-黄色网址你懂的-黄色网址有那些-免费超爽视频-免费大片黄国产在线观看

Java8新特性
Java9新特性

Java8新增java.time包

java.util.Date日期類不是線程安全的。

在JDK8中引入了線程安全的時間類。

package com.wkcto.time;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.time.temporal.ChronoUnit;

/**
 * java.time包中線程安全的日期類
 * Author : 動力節點老崔
 */
public class Test {
    public static void main(String[] args) {
        //1)LocalDate日期類
        LocalDate date = LocalDate.now();   //當前日期
        System.out.println( date );     //2019-04-24

        //2)當前時間
        LocalTime time = LocalTime.now();
        System.out.println( time );     //19:50:35.344

        //3)日期與時間
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);        //2019-04-24T19:51:03.726

        //4)返回當前日期的各個屬性值
        System.out.println( now.getYear());
        System.out.println( now.getMonthValue());
        System.out.println( now.getDayOfMonth());
        System.out.println( now.getHour());
        System.out.println( now.getMinute());
        System.out.println( now.getSecond());
        System.out.println( now.getNano());     //在毫秒數后面添加6個0

        //5)自定義時間
        LocalDateTime another = LocalDateTime.of(2100, 10, 12, 8, 58, 28);
        System.out.println( another );

        //6)使用plus增加時間, minus可以減少時間
        another = another.plusYears(1);
        System.out.println(another);

        another = another.plusMonths(1);
        System.out.println(another);

        another = another.plusDays(1);
        System.out.println(another);

        another = another.plusHours(1);
        System.out.println(another);

        another = another.plusMinutes(1);
        System.out.println(another);

        another = another.plusSeconds(1);
        System.out.println(another);

        another = another.plus(10, ChronoUnit.YEARS);
        System.out.println(another);

        //7)設置時間
        another = another.withYear(2088);
        another = another.withMonth(7);
        System.out.println( another);

        //8)判斷星期幾
        System.out.println( another.getDayOfWeek());

        //9)把日期轉換為指定格式的字符串
        DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG);
        //LocalDateTime類中有一個format( DateTimeFormatter) 實例方法可以把日期轉換為指定格式字符串
        System.out.println( now.format(formatter) );        //2019年4月24日 下午08時03分28秒

        formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT);
        System.out.println( now.format(formatter));     //19-4-24 下午8:03

        //自定義日期格式: y年, M月 d日 H小時 m分鐘 s秒 S毫秒
        formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss SSS");
        System.out.println( now.format(formatter));  //2019年04月24日 20:05:16 338

        //10)把字符串轉換為日期
        String text = "2089年8月12日 8:28:58";
        formatter = DateTimeFormatter.ofPattern("yyyy年M月dd日 H:mm:ss");
        // LocalDateTime.parse(text, formatter)靜態方法,可以把text文件以formatter格式轉換為日期對象
        another = LocalDateTime.parse(text, formatter);
        System.out.println(another);

    }
}

 

全部教程
主站蜘蛛池模板: 色哟哟在线网站 | 最近2019好看的中文字幕免费 | 成人a免费α片在线视频网站 | 农村偷人一级超爽毛片 | 麻豆久久婷婷综合五月国产 | 国产一区二区高清 | 欧美播放 | 99在线精品日韩一区免费国产 | 在线成人爽a毛片免费软件 在线成人影片 | 国产精品日韩在线观看 | 欧美成人高清 | 在线欧美亚洲 | 精品国产日韩亚洲一区二区 | 91精品成人免费国产 | 在线观看欧美日韩 | 日韩爆操| 一本三道a无线码一区v小说 | 精品中文字幕一区二区三区四区 | 久久怡红院亚欧成人影院 | 日本不卡视频一区二区三区 | 日韩ab| 亚洲另类图 | 中文字幕手机在线视频 | 亚洲伊人久久综合影院2021 | 日韩专区欧美 | www小视频| 免费人成大片在线观看播放 | caopor牛牛射在线| 欧美精品第1页www劲爆 | 在线播放黄色片 | 欧美在线成人免费国产 | 交性大片欧美多人 | 诱人的护士5中文字幕 | 一级做a爱免费观看视频 | 国产成 人 综合 亚洲绿色 | 久操视频在线观看免费 | 欧美日韩在线高清 | 丁香天堂| 欧美一级高清免费a | 亚洲美女综合网 | 在线 | 一区二区三区四区 |