日期:2014-05-18 浏览次数:21053 次
Calendar c = Calendar.getInstance(); //第一天 c.set(Calendar.DATE,1); //最后一天 int max = c.getActualMaximum(Calendar.DATE); c.set(Calendar.DATE,max);
------解决方案--------------------
用javascript控制一下啊
function changDate(theStr){
var returnStr;
var the5Str;
the5Str = theStr.subSring(5);
if(theStr != null && theStr != ""){
if(the5Str != "02"){
if(the5Str=="1" || the5Str ="3" || the5Str ="5"|| the5Str ="7"||
the5Str ="8"|| the5Str ="10" || the5Str ="12"){
returnStr = theStr +"01-"+theStr+"30"
}else{
returnStr = theStr +"01-"+theStr+"31"
}
}else{
returnStr = theStr +"01-"+theStr+"29"
}
}
}
------解决方案--------------------
var myDate= new Date(); var s1 = myDate.getYear() + "-" + myDate.getMonth + "-01";//第一天 var s2 = myDate.getYear() + "-" + myDate.getMonth + "-" + myDate.getDate();//最后一天
------解决方案--------------------
更正:
var myDate= new Date(); var s1 = myDate.getYear() + "-" + myDate.getMonth() + "-01";//第一天 var s2 = myDate.getYear() + "-" + myDate.getMonth() + "-" + myDate.getDate();//最后一天
------解决方案--------------------
膜拜LZ
------解决方案--------------------
package com.dm.sck.action.audit; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class A { /** * 给一个日期,根据这个日期该日期月的起止日期 * @throws ParseException * */ public static void main(String[] args) throws ParseException { // TODO Auto-generated method stub Calendar cal = A.transStringToCalendar("yyyy-MM-dd", "2009-12-15"); int maxdate = cal.getActualMaximum(Calendar.DATE); int mindate = cal.getActualMinimum(Calendar.DATE); cal.set(Calendar.DATE, maxdate); Date max = cal.getTime(); String maxStr = A.transDateToString("yyyy-MM-dd", max); System.out.println("最大日期: " + maxStr); cal.set(Calendar.DATE, mindate); Date min = cal.getTime(); String minStr = A.transDateToString("yyyy-MM-dd", min); System.out.println("最小日期: " + minStr); } /** * 将data转为string * */ public static String transDateToString(String format, Date date) { if (date == null) return " "; SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.