zoukankan      html  css  js  c++  java
  • 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("=================================================");
    
        }
    }
    

  • 相关阅读:
    执行makemigrations后错误集锦
    Django+xadmin的安装与配置
    MyEclipse Web项目部署失败:Deployment failure on Tomcat 7.x.Could not copy all resources to XXX.
    用户场景描述
    <packaging>pom</packaging>
    Tomcat的3种部署方式
    camelCase骆驼拼写法
    What does ‘composer dump-autoload’ do in Laravel?
    empty方法
    php页面meta头设置
  • 原文地址:https://www.cnblogs.com/klvchen/p/15226767.html
Copyright © 2011-2022 走看看