商城首页欢迎来到中国正版软件门户

您的位置:首页 >java如何使用YearMonth组合类

java如何使用YearMonth组合类

  发布于2023-05-02 阅读(0)

扫一扫,手机访问

如何表示信用卡到期这类固定日期,答案就在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);      
}  
}
本文转载于:https://www.yisu.com/zixun/480309.html 如有侵犯,请联系zhengruancom@outlook.com删除。
免责声明:正软商城发布此文仅为传递信息,不代表正软商城认同其观点或证实其描述。

热门关注