获取前一天日期:
Calendar c = Calendar.getInstance();
c.add(Calendar.DATE,-1);
Date date = c.getTime();
system.out.println(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(date));
秒转化为天小时分秒字符串:
public static String formatSeconds(long seconds) {
String timeStr = seconds + "秒";
if (seconds > 60) {
long second = seconds % 60;
long min = seconds / 60;
timeStr = min + "分" + second + "秒";
if (min > 60) {
min = (seconds / 60) % 60;
long hour = (seconds / 60) / 60;
timeStr = hour + "小时" + min + "分" + second + "秒";
if (hour > 24) {
hour = ((seconds / 60) / 60) % 24;
long day = (((seconds / 60) / 60) / 24);
timeStr = day + "天" + hour + "小时" + min + "分" + second + "秒";
}
}
}
return timeStr;
}
日期判空和比较:
<input name="startTime" id="startTime" value="${startTime }" size="15" editable="false"/>
<input name="endTime" id="endTime" value="${endTime }" size="15" editable="false"/>
var startTime = $('input[name=startTime]').val();
var endTime = $('input[name=endTime]').val();
if(startTime == ""|| endTime == ""){
parent.layer.open({icon:2,title: '提示信息',content: '请输入开始时间和结束时间!!!'});
return ;
}
if(startTime > endTime){
parent.layer.open({icon:2,title: '提示信息',content: '结束日期不能早于开始日期!!!'});
return ;
}