Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 java.sql.date 的日期计算问题
jerry010





发贴: 17
积分: 0
于 2004-09-05 22:05 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
通过java.sql.date可以计算日期的,可是遇到一个问题:
就是8月31日等几个月末使用java.sql.date(date.getYear,date.getMonth+1,date.getDate)得出月份的结果是下两个月的返回值,如2004/08/31-->2004/10
何故啊?如何解决?谢谢



作者 Re:java.sql.date 的日期计算问题 [Re:jerry010]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2004-09-05 22:33 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
1. java.sql.Date(int year, int month, int day) is deprecated.
use java.util.Calendar

2. 2004/08/31 --(month + 1)--> 2004/09/31
but 2004/09 does not have the 31st day, so the result is 2004/10/01



作者 Re:java.sql.date 的日期计算问题 [Re:jerry010]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2004-09-06 08:28 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
java.sql.Date(date.getYear(),date.getMonth()+1,date.getDate())

you don't have to add 1 to date,getMonth()
since both java.sql.Date(int,int,int) and java.util.Date(int,int,int) expects the month value from 0 to 11

check http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Date.html#Date(int,%20int,%20int)
and http://java.sun.com/j2se/1.4.2/docs/api/java/util/Date.html#Date(int,%20int,%20int)


why edited on 2004-09-06 08:30


flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923