常用日期解决方案
来源:互联网 发布:哈工大深圳知乎 编辑:程序博客网 时间:2024/05/01 06:58
当前日期加一个月 :
Calendar a = Calendar.getInstance();
a.add(Calendar.MONTH,1);
long sdate=a.getTimeInMillis();
java.sql.Date sdate1=new java.sql.Date(sdate);
System.out.println(sdate1);
得到当前日期和以前日期之间的天数 :
public static int getTodayCount(Date oldDate) {
long day = 1000 * 60 * 60 * 24;
Date today = new Date();
long todayTime = today.getTime();
long oldTime = oldDate.getTime();
int result = (int) ((todayTime - oldTime) / day + 1);
return result;
}
构造一个日历:
public static int[][] buildCalendar(Calendar cal) {
cal.set(Calendar.DAY_OF_MONTH, 1);
int firstDateInWeek = cal.get(Calendar.DAY_OF_WEEK) - 1;
int dateOfMonth = getMonthDateCount(cal);
int base = dateOfMonth + firstDateInWeek;
int row = base / 7;
row += ((base % 7) > 0) ? 1 : 0;
int[][] cals = new int[row][7];
int iCol = firstDateInWeek, iRow = 0;
for (int i = 1; i <= dateOfMonth; i++) {
cals[iRow][iCol] = i;
if (iCol == 6) {
iCol = 0;
iRow++;
} else
iCol++;
}
return cals;
}
得到这个月的天数:
public static int getMonthDateCount(Calendar cal) {
Calendar cal2 = (Calendar) cal.clone();
cal2.add(Calendar.MONTH, 1);
cal2.set(Calendar.DAY_OF_MONTH, 1);
cal2.add(Calendar.DAY_OF_MONTH, -1);
return cal2.get(Calendar.DAY_OF_MONTH);
}
Calendar a = Calendar.getInstance();
a.add(Calendar.MONTH,1);
long sdate=a.getTimeInMillis();
java.sql.Date sdate1=new java.sql.Date(sdate);
System.out.println(sdate1);
得到当前日期和以前日期之间的天数 :
public static int getTodayCount(Date oldDate) {
long day = 1000 * 60 * 60 * 24;
Date today = new Date();
long todayTime = today.getTime();
long oldTime = oldDate.getTime();
int result = (int) ((todayTime - oldTime) / day + 1);
return result;
}
构造一个日历:
public static int[][] buildCalendar(Calendar cal) {
cal.set(Calendar.DAY_OF_MONTH, 1);
int firstDateInWeek = cal.get(Calendar.DAY_OF_WEEK) - 1;
int dateOfMonth = getMonthDateCount(cal);
int base = dateOfMonth + firstDateInWeek;
int row = base / 7;
row += ((base % 7) > 0) ? 1 : 0;
int[][] cals = new int[row][7];
int iCol = firstDateInWeek, iRow = 0;
for (int i = 1; i <= dateOfMonth; i++) {
cals[iRow][iCol] = i;
if (iCol == 6) {
iCol = 0;
iRow++;
} else
iCol++;
}
return cals;
}
得到这个月的天数:
public static int getMonthDateCount(Calendar cal) {
Calendar cal2 = (Calendar) cal.clone();
cal2.add(Calendar.MONTH, 1);
cal2.set(Calendar.DAY_OF_MONTH, 1);
cal2.add(Calendar.DAY_OF_MONTH, -1);
return cal2.get(Calendar.DAY_OF_MONTH);
}
- 常用日期解决方案
- 农历日期控件解决方案
- PHP+MYSQL日期终极解决方案
- Delphi常用日期函数
- 日期操作常用代码
- sqlserver 常用日期格式化
- sql常用日期
- SqlServer常用日期格式
- Oracle 常用日期函数
- javascript常用日期验证
- oracle 常用日期计算
- oracle 常用日期计算
- Oracle 常用日期函数
- 日期操作常用代码
- Oracle常用日期函数
- javascript 日期常用函数
- [Delphi] 常用日期函数
- oracle 常用日期函数
- win2000server IIS和tomcat5多站点配置
- menu4做的菜单在IE7下的变形问题
- Visual style theme
- New features in C# 2.0
- 从Table 表中取出第 m 条到第 n 条的记录:(Not In 版本)
- 常用日期解决方案
- 远程抓取页面信息并解析XML
- AJAX 中文支持模板(jsp)
- (转)怎样建立全文索引
- 如何控制excel单元格的数据类型
- html表格滚动条的实现代码
- 删除重复记录
- C#正则学习杂谈(一)
- DotNet ajax frame