zoukankan      html  css  js  c++  java
  • Java8 本地DateTime API

    LocalDate/本地时间和LocalDateTime类简化时区不需要开发。

    让我们来看看他们操作。

    选择使用任何编辑器创建以下java程序在 C:/> JAVA

    Java8Tester.java

    import java.time.LocalDate;import java.time.LocalTime;import java.time.LocalDateTime;import java.time.Month;public class Java8Tester {
       public static void main(String args[]){
          Java8Tester java8tester = new Java8Tester();
          java8tester.testLocalDateTime(); 
       }
    
       public void testLocalDateTime(){
          // Get the current date and time
          LocalDateTime currentTime = LocalDateTime.now();     
          System.out.println("Current DateTime: " + currentTime);
    
          LocalDate date1 = currentTime.toLocalDate();
          System.out.println("date1: " + date1);
          Month month = currentTime.getMonth();
          int day = currentTime.getDayOfMonth();
          int seconds = currentTime.getSecond();
          System.out.println("Month: " + month         +"day: " + day         +"seconds: " + seconds      );
    
          LocalDateTime date2 = currentTime.withDayOfMonth(10).withYear(2012);
          System.out.println("date2: " + date2);
    
          //12 december 2014
          LocalDate date3 = LocalDate.of(2014, Month.DECEMBER, 12); 
          System.out.println("date3: " + date3);
    
          //22 hour 15 minutes
          LocalTime date4 = LocalTime.of(22, 15); 
          System.out.println("date4: " + date4);
    
          //parse a string
          LocalTime date5 = LocalTime.parse("20:15:30"); 
          System.out.println("date5: " + date5);
       }	}

    验证结果

  • 相关阅读:
    Dapper and Repository Pattern in MVC
    在linux中使用多个redis端口来构建redis集群
    搭建Sql Server AlwaysOn 视频教程
    支付宝支付插件使用文档
    NopCommerce添加事务机制
    NopCommerce(3.9)作业调度插件
    微信扫码支付插件使用文档
    生成HTML表格的后台模板代码
    json字符串和字典类型的相互转换
    NopCommerce适应多数据库方案
  • 原文地址:https://www.cnblogs.com/hane/p/7356610.html
Copyright © 2011-2022 走看看