我用的是
Date postDate=rs.getDate("PostDate");
int year=postDate.getYear();
int month=postDate.getMonth();但警告说不建议使用此方法。看帮组文档说好像过时了什么的。谁能说一下这么做?
Date postDate=rs.getDate("PostDate");
int year=postDate.getYear();
int month=postDate.getMonth();但警告说不建议使用此方法。看帮组文档说好像过时了什么的。谁能说一下这么做?
具体可看文档
cal.setTime(postDate);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
去读一读API文档中关于Calendar的部分
不建议并不代表不能用啊?个人习惯了,我喜欢Calendar 方便。
对日期的操作一般都用Calendar,
关于这两个可以看一下这篇文档的介绍
http://www.51cto.com/specbook/24/6720.htm
calendar.setTime(postDate);
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
用的时候注意就是了,不要让BUG出来就可以用了。
month要+1的好像
另外警告的方法也可能是太老了有可以替换的方法出来,不建议使用
currentCal.add(java.util.Calendar.DAY_OF_MONTH, 1);
java.text.SimpleDateFormat df = new java.text.SimpleDateFormat ("yyyy/MM/dd");
String sTomorrow = df.format(currentCal.getTime());
改用这个了,.,,....
用Calendar取日期,
用SimpleDateFormat 来格式化。public static String getTime(String format)
{
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(cal.getTime());
}这是我刚写的方法,传一个你要的格式即可。希望有所帮助!