大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

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);

    }
}

 

全部教程
主站蜘蛛池模板: 久久精品国产精品青草不卡 | 日欧毛片| 国产精品 第二页 | 国产免费a视频 | 国产91福利在线精品剧情尤物 | 欧美一级艳片视频免费观看 | 欧美日韩小视频 | 韩日视频在线观看 | 天天干在线免费视频 | 欧美日韩国产片 | 久久午夜影院 | 国产精品久久久久久爽爽爽 | 成人影院观看 | 狠狠热精品免费观看 | 精品欧美一区二区三区免费观看 | 免费福利视频网站 | 欧美日韩在线播放一区二区三区 | 中文字幕一区日韩在线视频 | 欧美精品成人免费视频 | 久久久久国产成人精品 | 欧美日韩性大片 | 国产四虎免费精品视频 | 久久视频免费在线观看 | 99视频在线 | 91精品国产色综合久久不 | 天天做日日做 | 四虎永久在线精品国产 | 中文字幕97 | 日日夜夜操操 | 91热久久免费精品99 | 看免费黄色一级视频 | 在线视频中文 | 这里只有精品免费视频 | 国产成人精品日本亚洲直接 | 欧美一级欧美三级在线观看 | 久久久久久久久免费影院 | videoxxoo欧美老师 | 超级97碰碰碰碰久久久久最新 | 亚洲欧美日韩中文在线 | 天天综合欧美 | 国产精品99久久久久久人 |