网站首页
JSP空间
动态资讯
开源项目
技术文档
资源下载
J2EE资源
客户论坛
在线支付
 
  技术文档>>JAVA>>新手入门>>基础入门>查看文档  
  使用java.util.calendar返回间隔天数     
  文章作者:未知  文章来源:水木森林  
  查看:141次  录入:管理员--2007-11-17  
 
  使用simpledateformat,规定好格式,parser出错即为非法/** * calculates the number of days between two calendar days in a manner * which is independent of the calendar type used. * * @param d1    the first date. * @param d2    the second date. * * @return      the number of days between the two dates.  zero is *              returned if the dates are the same, one if the dates are *              adjacent, etc.  the order of the dates *              does not matter, the value returned is always >= 0. *              if calendar types of d1 and d2 *              are different, the result may not be accurate. */static int getdaysbetween (java.util.calendar d1, java.util.calendar d2) {    if (d1.after(d2)) {  // swap dates so that d1 is start and d2 is end        java.util.calendar swap = d1;        d1 = d2;        d2 = swap;    }    int days = d2.get(java.util.calendar.day_of_year) -               d1.get(java.util.calendar.day_of_year);    int y2 = d2.get(java.util.calendar.year);    if (d1.get(java.util.calendar.year) != y2) {        d1 = (java.util.calendar) d1.clone();        do {            days += d1.getactualmaximum(java.util.calendar.day_of_year);            d1.add(java.util.calendar.year, 1);        } while (d1.get(java.util.calendar.year) != y2);    }    return days;}
 
 
上一篇: 使用java server faces技术自定义组件    下一篇: 使用javaexcel api 往excel中插入图片
  相关文档
浅析java的流 11-17
保存java程序状态及设置之properties文件 11-17
ajax实现分页查询 11-17
实例变量与存取方法 11-17
struts的异常处理机制 11-17
对于实现java平台的三种方式的详细解析 11-16
xde中模式驱动的设计与开发(二) 11-17
怎样让窗口始终在前 11-17
编程需要注意陷阱:java继承是有害的 11-17
用j2me midp开发无线应用程序 11-17
java常用加密算法应用md5,sha,rsa 11-17
java设计模式和软件工程之designpattern介绍 11-17
in software that use java, show popmenu that have the func.. 11-17
用jbuilder9开发媒体播放器 11-17
java从入门到精通之过程篇 11-17
走出abstract class与interface的困惑 11-17
vj6.0的使用方法(5)applet编写调试过程 11-16
i/o及网络--一个简单的文件传送代码 01-11
sun java wireless toolkit 2.3 beta新特性 11-17
正确优雅的解决用户退出问题(转自http://www.jdon.com) 11-17
返回首页 | 关于我们 | J网章程 | JSP空间合租 | 客服中心 | 免责声明 | 常见问题 | 参观机房
本站主机空间代理至厦门市华众网络科技有限公司
《中华人民共和国增值电信业务经营许可证》
编号:闽B2-20050079
@2005-2008福建JSP技术网 版权所有 闽ICP备05000928号
技术电话:13616026886
邮箱:admin@fjjsp.com 站长QQ,点击这里给我发消息