我是编程的新手,我想知道下面写的两种方式,哪一种更好/更好的方法,为什么?
代码是在指定日期添加给定天数,并在单选按钮列表中选择天数时在输入框中插入新日期
HTML 的
for(ParseObject singleClaim : resultsList){
//If the customerStatus is 5, we check to see if the updatedTime is within 24 Hours.
if(singleClaim.getInt("customerStatus") == 5) {
//Create a date formatter.
SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd'T'HH':'mm':'ss'.'SSS'Z'");
//Create a date object for today's date.
Date currentDate=new Date();
//Create a string for the date from parse.
String parseTime = singleClaim.getString("updatedAt");
//Initialize the date object for the updatedAt time on Parse.
Date parseDate = null;
try {
//Here, we convert the parseTime string into a date object and format it.
parseDate = formatter.parse(parseTime);
}
catch (Exception e) {
e.printStackTrace();
}
//Get the time difference from the current date versus the date on Parse in milliseconds.
long difference = currentDate.getTime() - parseDate.getTime();
for(int i=1;;i++ ){
//If the time difference is more than 24 hours in milliseconds, we print out the claim number.
if(difference>86400000){
System.out.println(i + ".)" + singleClaim.getString("claimNumber"));
}
else {
break;};
}
}}
System.out.println("\n////////////////////////////////////////////////////////");
System.out.println("Done getting claims with customerStatus of 5 updated over 24 hours ago.");
System.out.println("///////////////////////////////////////////////////////\n");
}
catch(Exception e){
e.printStackTrace();
}}}
jQuery(第一个)
Old Date (MM/DD/YYYY) : <input type="text" id="date1" /><br><br>
<input type="radio" name="expiry" id="allot" value="5" onchange="dateChange()">5 Days
<input type="radio" name="expiry" id="allot" value="10" onchange="dateChange()" >10 Days <br> <br>
New Date (MM/DD/YYYY) : <input type="text" id="date2"/><br><br>
jQuery(第二个)
function dateChange(){
var days = $('input[type=radio][name=expiry]').val();
var myDate =new Date($("#date1").val());
myDate.setDate(myDate.getDate()+parseInt(days));
var inputDate = (myDate.getMonth()+1)+'/'+(myDate.getDate())+'/' (myDate.getFullYear());
$("#date2").val(inputDate);
}
提前谢谢。