• 技术文章 >Java >java教程

    Java中如何使用YearMonth类组合日期和时间

    王林王林2023-04-24 22:58:05转载31

    如何表示信用卡到期这类固定日期,答案就在YearMonth

    与 MonthDay检查重复事件的例子相似,YearMonth是另一个组合类,用于表示信用卡到期日、FD到期日、期货期权到期日等。还可以用这个类得到 当月共有多少天,YearMonth实例的lengthOfMonth()方法可以返回当月的天数,在判断2月有28天还是29天时非常有用。

    package com.shxt.demo02;  
    import java.time.*;  
    public class Demo13 {      
    public static void main(String[] args) {          
    YearMonth currentYearMonth = YearMonth.now();          
    System.out.printf("Days in month year %s: %d%n", currentYearMonth, currentYearMonth.lengthOfMonth());          
    YearMonth creditCardExpiry = YearMonth.of(2019, Month.FEBRUARY);          
    System.out.printf("Your credit card expires on %s %n", creditCardExpiry);      
    }  
    }

    以上就是Java中如何使用YearMonth类组合日期和时间的详细内容,更多请关注php中文网其它相关文章!

    声明:本文转载于:亿速云,如有侵犯,请联系admin@php.cn删除
    专题推荐:Java YearMonth
    上一篇:Java设计模式:策略模式及实现方法详解 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • Java RabbitMQ高级特性实例分析• Java线程安全与同步实例分析• Java反射的示例分析• PHP和Java des的加密解密实例分析• JAVA开发中常用的工具有哪些
    1/1

    PHP中文网