传入两个时间如何得出 两个时间相差多少月呢 如String bejintime="2006-02";
String endtime="2007-09"; 可以得到,我要的到之间的具体 年 月 集合 2006-02 ,2006-03,2006-04 。一直到2007-09
String endtime="2007-09"; 可以得到,我要的到之间的具体 年 月 集合 2006-02 ,2006-03,2006-04 。一直到2007-09
解决方案 »
- Java 动画的问题 求高手指点
- BufferedImage类的createGraphcs2D()方法怎么用?
- java更新firebird数据库数据时报错
- JDBC中DatabaseMetaData#getSchemas()
- jsp如何更新mysql日期数据
- 急救...
- 请教超级弱智关于JComboBox的
- 求邮箱(字符串)的验证算法。
- javax.mail.AuthenticationFailedException: failed to connect
- 请问,中文输入法在一个组件上是否可输取决什么?
- 父类名 引用 = new 子类名()与 子类名 引用 = new 子类名()有什么区别啊?
- 求助,如何的出两个时间之间相差多少个月????
import java.text.*;
public class Time { /**
* @param args
*/
public static void main(String[] args) throws ParseException{
// TODO Auto-generated method stub
String time = "2006-02";
String time2 = "2007-09";
DateFormat df = new SimpleDateFormat("yyyy-MM");
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
c1.setTime(df.parse(time));
c2.setTime(df.parse(time2));
ArrayList<String> list = new ArrayList<String>();
while(!c1.after(c2)){
list.add(df.format(c1.getTime()));
c1.add(Calendar.MONTH, 1);
}
System.out.println(list);
}}