在jsp中得到当前月份的第一天与最后一天(急)
在jsp中得到当前月份的第一天与最后一天(急)
用out.print();输出,
另在文本框中输入当前月份,点击按钮
出现当前月份的第一天与最后一天,
如输入2008-03时将显示2008-03-01与2008-03-31
当输入2008-02时将显示2008-02-01与2008-02-29
[解决办法]
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.format(date); } /** * 将string转为Calendar * */ public static Calendar transStringToCalendar(String format, String str_date) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat(format); java.util.Date d = sdf.parse(str_date); Calendar cal = Calendar.getInstance(); cal.setTime(d); return cal; }}
[解决办法]
那你就再加一层判断了 看年份是不是闰年啊
你要学会思考啊 不能什么都别人告诉你啊 对你的学习不好
[解决办法]
关注中...
[解决办法]
//在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{
if(判断是否闰年(theStr.subSring(0,4))){
returnStr = theStr +"01-"+theStr+"28"
}else{
returnStr = theStr +"01-"+theStr+"29"
}
}
}
去网上找个判断闰年的函数 很多的 就我刚才给你的多加了一个判断
要学会用google 和百度 啊
}
[解决办法]
取当月的第一天:
java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-01"); java.util.Date firstDay=new java.util.Date(); System.out.println("the month first day is "+formats.format(firstDay));
[解决办法]
顶一下,做个标记
[解决办法]
做个标记