java輸入年月日判斷第幾天 java怎么比較兩個日期(年和月)的大???
java怎么比較兩個日期(年和月)的大???1. 獲取日期函數(shù)int getyearmonth(date DT)的月份和年份{//pass in the date calendar=日歷.getInst
java怎么比較兩個日期(年和月)的大?。?/h2>
1. 獲取日期函數(shù)int getyearmonth(date DT)的月份和年份{//pass in the date calendar=日歷.getInstance() 校準(zhǔn)設(shè)定時間( 日期:getTime())//設(shè)置時間int year=卡爾·蓋特( 日歷年)//獲取年份int month=卡爾·蓋特( 日歷.月)//Get the month return year*100 month//返回該年的值乘以100加上月份。因為月份最多有兩位數(shù),所以年乘以100可以得到唯一的月份和年份值}2。比較日期int D1=getyearmonth(New date())int D2=getyearmonth(New date())if(D1==D2){//month和year相等}else if(D1>d2){//D1晚于D2}else{//D1早于D2}
比較gettime得到的整數(shù)值。整數(shù)值大的時候是大的,整數(shù)值小的時候是小的。例如:public int comparedate(date D1,date D2){if(dt1)。Gettime()> DT2。Gettime()){系統(tǒng)輸出打?。ā癲t1 before DT2”)返回1}else if(dt1。Gettime()< DT2。Gettime()){系統(tǒng)輸出打印(“dt1 after DT2”)return-1}否則{//equal return 0}