📄 calculatedaysbetweendates.java
字号:
package librarymanagement.common;
/**
* 获得两个String类型的日期相隔的天数
* @author 虎兴龙
*
*/
public class CalculateDaysBetweenDates {
/**
*
* @param date1
* @param date2
* @return 返回两个字符串类型日期相隔的天数,后者大于前者怎返回负值
*/
public static long calculateDaysBetweenDates(String date1,String date2){
long days=0;
int i1=Integer.parseInt(date1.substring(0, 4));
int i2 = Integer.parseInt(date2.substring(0,4));
int betweenYear=i2-i1;
int m1= Integer.parseInt(date1.substring(5, 7));
int m2 = Integer.parseInt(date2.substring(5, 7));
int betweenMons = m2-m1;
int d1 = Integer.parseInt(date1.substring(8, 10));
int d2 = Integer.parseInt(date2.substring(8, 10));
int betweenDays = d2-d1;
days = betweenYear*365 + betweenMons*30 + betweenDays;
return days;
}
/*public static void main(String[] args){
System.out.println(calculateDaysBetweenDates("2009-11-16","2008-12-15"));
}*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -