jsp中如何计算两个时间差? 数据库中保存的是varchar型的 30/Dec/2007:04:47:33 +0800 这种时间,如何取出并计算两个相临的时间差看是否大于30分钟 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public boolean getQuot(String time1) { boolean bool = false; long quot = 0; SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd"); try { Date date1 = ft.parse(time1); Date date2 = new Date(); if(date1.getTime()<date2.getTime()){ quot = date2.getTime()- date1.getTime(); quot = quot / 1000 / 60 / 60 / 24; if(quot>0){ bool = false; }else{ bool = true; } }else{ bool = false; } } catch (ParseException e) { e.printStackTrace(); } return bool;} 请参考import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;import java.util.Locale;public class Test { private static final SimpleDateFormat format = new SimpleDateFormat("dd/MMM/yyyy HH:mm:ss Z", Locale.US); public static Date getDate(String str) throws ParseException { return format.parse(str); } public static void main(String[] args) throws ParseException { String str1 = "30/Dec/2007 04:47:33 +0800"; String str2 = "30/Dec/2007 05:17:33 +0800"; long d1 = getDate(str1).getTime(); long d2 = getDate(str2).getTime(); System.out.println((d2 - d1) > 30 * 60 * 1000); }} struts2中文乱码问题,我可咋办啊…………>_< unexpected end of subtree 原因是什么 在线考试系统——填空题 java菜鸟求提升之道 jsp连接数据库的问题 为什么用jsp做的网站这么少? JS的问题,谢谢帮忙,解决了就给分。。 小弟在家写一个隐藏表单!出现了些问题!还请各位大大帮忙解答一下! 哪位能邦忙解释.没有基础.只会VBSCRIPT 如何捕获一个程序非正常关闭的异常 这关于Session吗? 老问题: <html:errors>不显示错误信息,查了网上的方法,还是不行
public boolean getQuot(String time1) {
boolean bool = false;
long quot = 0;
SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
try {
Date date1 = ft.parse(time1);
Date date2 = new Date();
if(date1.getTime()<date2.getTime()){
quot = date2.getTime()- date1.getTime();
quot = quot / 1000 / 60 / 60 / 24;
if(quot>0){
bool = false;
}else{
bool = true;
}
}else{
bool = false;
}
} catch (ParseException e) {
e.printStackTrace();
}
return bool;
}
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;public class Test {
private static final SimpleDateFormat format = new SimpleDateFormat("dd/MMM/yyyy HH:mm:ss Z", Locale.US); public static Date getDate(String str) throws ParseException {
return format.parse(str);
} public static void main(String[] args) throws ParseException {
String str1 = "30/Dec/2007 04:47:33 +0800";
String str2 = "30/Dec/2007 05:17:33 +0800";
long d1 = getDate(str1).getTime();
long d2 = getDate(str2).getTime();
System.out.println((d2 - d1) > 30 * 60 * 1000);
}
}