如何表示信用卡到期这类固定日期,答案就在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);      
}  
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。