• Java 基础(LocalDate, LocalTime, LocalDateTime)


    package com.klvchen.java;
    
    import org.junit.Test;
    
    import java.time.LocalDate;
    import java.time.LocalDateTime;
    import java.time.LocalTime;
    import java.util.Date;
    
    public class JDK8DateTimeTest {
    
        /*
        LocalDate, LocalTime, LocalDateTime 的使用
         */
    
        @Test
        public void test1(){
            LocalDate localDate = LocalDate.now();
            LocalTime localTime = LocalTime.now();
            LocalDateTime localDateTime = LocalDateTime.now();
    
            System.out.println(localDate);
            System.out.println(localTime);
            System.out.println(localDateTime);
            System.out.println("=================================================");
    
            //of():设置指定的年,月,日,时,分,秒,没有偏移量
            LocalDateTime localDateTime1 = LocalDateTime.of(2020, 10, 6, 13, 23, 43);
            System.out.println(localDateTime1);
            System.out.println("=================================================");
    
            //getXxx()
            System.out.println(localDateTime.getDayOfMonth());
            System.out.println(localDateTime.getDayOfWeek());
            System.out.println(localDateTime.getMonth());
            System.out.println(localDateTime.getMonthValue());
            System.out.println(localDateTime.getMinute());
            System.out.println("=================================================");
    
            //体现不可变性
            LocalDate localDate1 = localDate.withDayOfMonth(22);
            System.out.println(localDate);
            System.out.println(localDate1);
            System.out.println("=================================================");
    
            LocalDateTime localDateTime2 = localDateTime.withHour(4);
            System.out.println(localDateTime);
            System.out.println(localDateTime2);
            System.out.println("=================================================");
    
        }
    }
    

  • 相关阅读:
    RQNOJ 34 紧急援救
    Codevs 2080 特殊的质数肋骨
    POJ2975 Nim
    Bzoj1016 最小生成树计数
    POJ3613 Cow Relays
    POJ1386 Play on Words
    [从hzwer神犇那翻到的模拟赛题] 合唱队形
    HDU2824 The Euler function
    HDU1576 A/B
    HDU2669 Romantic
  • 原文地址:https://www.cnblogs.com/klvchen/p/15226767.html
Copyright © 2020-2023  润新知