java日期比较&表单提交

public static void main(String arg[]) throws ParseException{
/*java.util.Date nowdate=new java.util.Date();
String myString = "2008-09-08";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
Date d = sdf.parse(myString);
boolean flag = d.before(nowdate);
if(flag)
System.out.print("早于今天");
else
System.out.print("晚于今天");
if(d.getTime() > nowdate.getTime()){
System.out.println("晚于今天");
}
if(d.getTime() < nowdate.getTime()){
System.out.println("早于今天");
} */
String myString = "2013-07-20";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd",Locale.CHINA);
String now = sdf.format(new Date());
System.out.println(myString);
System.out.println(now);
if(java.sql.Date.valueOf(myString).after(java.sql.Date.valueOf(now))){
System.out.println("yew");
}else{
System.out.println("no");
}
if(myString.compareTo(now)>0){
System.out.println("111");
} else{
System.out.println("22222");
}
日期比较有两种,要么直接Date类型比较,要么转换成String比较。个人推荐后者~

二、表单提交
    当在jsp页面的form表单中存在两个或以上的button,要提交内容到同一个action的时候可以通过js来传值
function saveAdd(flag){
var obj = document.getElementsByName("form1");
var org=Validator.Validate(document.forms[0],3);
if(flag=='SAVE'){   // 保存
$("#statusChar").val('false');
$("#flag").val('0');
}else if(flag=='SHARE'){  // 共享
$("#statusChar").val('true');
$("#flag").val('1');
}
if(org){
if (obj != null && obj.length > 0)
{
obj[0].action = "<c:url value='/manage/file/fileupload.jhtml'/>";
obj[0].submit();
}

}else{
return;
}
}

<form name="form1" method="post" action="fileupload.jhtml" enctype="multipart/form-data" onsubmit="return Validator.Validate(this,3);">
<input name="file.status" id="statusChar"  type="hidden" value="" />
<input name="file.flag" id="flag"  type="hidden" value="" />
<div class="mT10">
<span class="btn05 mL10"> <input type="button" value="保存" onclick="saveAdd('SAVE');"/></span>
<span class="btn05 mL10"> <input type="button" value="共享" onclick="saveAdd('SHARE');"/></span>
</div>
</form>

你可能感兴趣的:(java)