时间的比较 如何比较两个时间,当现在时间与指定时间相差X时,执行A,当现在时间与指定时间相差Y时,执行B,有没有什么比较天数的方法啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Date.getTime()获得一个long,再计算long/24L*3600L 就= 几天了. Date currentDate = new Date();long currentTime = currentDate.getTime();Date fixedDate //指定的时间long fixedTime = fixedDate.getTime();int differeceDay = (currentTime - fixedTime) / (60 * 60 * 24);if( differenceDay == x ) //then execute x.....else if(differenceDay == y) //the execute y...... 用DateFormat转一下你的时间字符串即可DateFormat sf = new SimpleDateFormat("yyyy年MM月d日")Date d = sf.parse("2006年10月1日"); 还是不对啊Date d = null; DateFormat sf = new SimpleDateFormat("yyyy年MM月d日"); try { d = sf.parse("2006年7月5日"); } catch (ParseException e) { e.printStackTrace(); } Date currentDate = new Date(); System.out.println(d); System.out.println(currentDate); long currentTime = currentDate.getTime(); Date fixedDate = d; long fixedTime = fixedDate.getTime(); int differeceDay = (int) (Math.abs(fixedTime - currentTime) / (60 * 60 * 24)); System.out.println(differeceDay);这样运行出来是Wed Jul 05 00:00:00 CST 2006Tue Jul 04 16:45:31 CST 2006301这是什么原因啊?? JComboBox值与显示文本的设置问题 各位大哥大姐来看看哪! 新手求取圣经 MS的JDBC连接多实例的SQLSERVER2000,连接url应该怎么写?急 高手进,文件末尾处理技巧问题 下午要去面试,希望各位用java的大哥们指导一下,好吗?拜托 请问如何清空JTextArea中的内容?100分马上送! 在文件中再次追加学生信息时,怎么实现序列号 是从之前已经有的开始,例如之前已经有2个学生,下次追加从3开始 java的int的两个类型相除,结果怎么取舍啊? 关于JAVA线程栈的局部变量问题 用正则表达式字符串判断中文 怎样知道一个文本文件里有多少行?
long currentTime = currentDate.getTime();
Date fixedDate //指定的时间
long fixedTime = fixedDate.getTime();
int differeceDay = (currentTime - fixedTime) / (60 * 60 * 24);
if( differenceDay == x )
//then execute x.....
else if(differenceDay == y)
//the execute y......
Date d = sf.parse("2006年10月1日");
Date d = null;
DateFormat sf = new SimpleDateFormat("yyyy年MM月d日");
try
{
d = sf.parse("2006年7月5日");
}
catch (ParseException e)
{
e.printStackTrace();
}
Date currentDate = new Date();
System.out.println(d);
System.out.println(currentDate);
long currentTime = currentDate.getTime();
Date fixedDate = d;
long fixedTime = fixedDate.getTime();
int differeceDay = (int) (Math.abs(fixedTime - currentTime) / (60 * 60 * 24));
System.out.println(differeceDay);这样运行出来是
Wed Jul 05 00:00:00 CST 2006
Tue Jul 04 16:45:31 CST 2006
301这是什么原因啊??