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

Java8新特性
Java9新特性

Java8新增java.time包

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

在JDK8中引入了線程安全的時(shí)間類。

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 : 動(dòng)力節(jié)點(diǎn)老崔
 */
public class Test {
    public static void main(String[] args) {
        //1)LocalDate日期類
        LocalDate date = LocalDate.now();   //當(dāng)前日期
        System.out.println( date );     //2019-04-24

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

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

        //4)返回當(dāng)前日期的各個(gè)屬性值
        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());     //在毫秒數(shù)后面添加6個(gè)0

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

        //6)使用plus增加時(shí)間, minus可以減少時(shí)間
        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)設(shè)置時(shí)間
        another = another.withYear(2088);
        another = another.withMonth(7);
        System.out.println( another);

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

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

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

        //自定義日期格式: y年, M月 d日 H小時(shí) 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)把字符串轉(zhuǎn)換為日期
        String text = "2089年8月12日 8:28:58";
        formatter = DateTimeFormatter.ofPattern("yyyy年M月dd日 H:mm:ss");
        // LocalDateTime.parse(text, formatter)靜態(tài)方法,可以把text文件以formatter格式轉(zhuǎn)換為日期對(duì)象
        another = LocalDateTime.parse(text, formatter);
        System.out.println(another);

    }
}

 

全部教程
主站蜘蛛池模板: 国产精品欧美日韩视频一区 | 天天干天天添 | 日批日韩在线观看 | 国产一区二区三区亚洲综合 | 香蕉视频在线网站 | 狠狠色噜噜狠狠狠米奇9999 | 四虎4hu永久免费 | 欧美爱爱爱爱免费视频 | 天天狠狠色综合图片区 | 精品精品国产欧美在线观看 | 国产精品亚洲二线在线播放 | 一级特黄牲大片免费视频 | 黄色日本视频 | 欧美一区二区在线 | 久久精品这里热有精品2015 | 99精品热线在线观看免费视频 | 看一下毛片 | 久久综合九色 | 欧美大片天天免费看视频 | 天天干成人网 | www.涩| 欧美成人在线视频 | 欧美成人精品免费播放 | 黄色毛片网站 | 久久久久久亚洲精品 | 曰曰啪天天拍视频在线 | 久久视频免费看 | 亚洲国产网 | 亚洲男人天堂久久 | 深夜福利影院 | 五月色婷婷六月噜噜 | 精品久久久日韩精品成人 | 日韩人成 | 天天天操 | 日本久久一区二区 | 国产精品福利视频手机免费观看 | 国产第一综合另类色区奇米 | 国内自拍一二三四2021 | 日日人人| 爱爱一区| 免费黄色小视频在线观看 |