征集时间判断方法 date1.getTime()-date2.getTime() <= 5*24*60*60*1000 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用于判断某一天是否8位标准日期public boolean isStandardDate(String sourceString) { String date = sourceString; if(date == null) { return false; } else if(date.length()!=8) { return false; } else if(!isNumber(date)) { return false; } else { String year = date.substring(0,4); String month = date.substring(4,6); String day = date.substring(6,8); if((month.compareTo("12")>0)||(month.compareTo("01")<0)||(day.compareTo("31")>0)||(day.compareTo("01")<0)) { return false; } else { int Year = Integer.parseInt(year); if(month.compareTo("08")<0) { if(month.equals("02")) { if((Year%4==0)&&((Year%100!=0))||(Year%400==0)) { if(day.compareTo("29")>0) { return false; } else { return true; } } else { if(day.compareTo("28")>0) { return false; } else { return true; } } } else { int Month = Integer.parseInt(month); if(Month%2==0) { if(day.compareTo("30")>0) { return false; } else { return true; } } else { return true; } } } else { int Month = Integer.parseInt(month); if(Month%2==0) { return true; } else { if(day.compareTo("30")>0) { return false; } else { return true; } } } } } } /**功能:日期调整。返回值:调整后的8位标准日期。 * @param sourceString * @param addDays */ public String dateAdjust(String sourceString, int addDays) { String returnString = sourceString; if(isStandardDate(sourceString)) { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); Date dt = sdf.parse(sourceString, new ParsePosition(0)); Calendar cal = Calendar.getInstance(); cal.setTime(dt); cal.add(cal.DATE, addDays); Date dt1 = cal.getTime(); StringBuffer strBuffer = new StringBuffer(); strBuffer.append(""); returnString = sdf.format(dt1, strBuffer, new FieldPosition(0)).toString(); } return returnString; } 靠,太复杂了SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd hhmm");try{ sdf.parse(strDate)}catch(ParseException){} 靠,太复杂了SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd hhmm");try{ sdf.parse(strDate) return true;}catch(ParseException){ return false;} JAVA的计算题 高手手帮忙看看 FAR HTML帮助制作 如何用swing设计一个 生产者消费者的模型呢?高手请进 初学JAVA,一个问题,请您帮忙。 JTextField的类型怎样才能转成double? 在Label 中显示时间 小妹请教StringTokenizer 高手们帮我看看吧(javaBean的问题),先谢过各位了 初学java,请指点! 请问用java开发手机短信软件,好不好?还是用delphi等好? 集合的交,并,和以及它们性能对比C的问题。 各位,请问怎么处理这样的多个关联数组,使其一一对应上?都进来看看,多谢了先!thanks
public boolean isStandardDate(String sourceString)
{
String date = sourceString;
if(date == null)
{
return false;
}
else if(date.length()!=8)
{
return false;
}
else if(!isNumber(date))
{
return false;
}
else
{
String year = date.substring(0,4);
String month = date.substring(4,6);
String day = date.substring(6,8);
if((month.compareTo("12")>0)||(month.compareTo("01")<0)||(day.compareTo("31")>0)||(day.compareTo("01")<0))
{
return false;
}
else
{
int Year = Integer.parseInt(year);
if(month.compareTo("08")<0)
{
if(month.equals("02"))
{
if((Year%4==0)&&((Year%100!=0))||(Year%400==0))
{
if(day.compareTo("29")>0)
{
return false;
}
else
{
return true;
}
}
else
{
if(day.compareTo("28")>0)
{
return false;
}
else
{
return true;
}
}
}
else
{
int Month = Integer.parseInt(month);
if(Month%2==0)
{
if(day.compareTo("30")>0)
{
return false;
}
else
{
return true;
}
}
else
{
return true;
}
}
}
else
{
int Month = Integer.parseInt(month);
if(Month%2==0)
{
return true;
}
else
{
if(day.compareTo("30")>0)
{
return false;
}
else
{
return true;
}
}
}
}
}
}
* @param sourceString
* @param addDays
*/
public String dateAdjust(String sourceString, int addDays)
{
String returnString = sourceString;
if(isStandardDate(sourceString))
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Date dt = sdf.parse(sourceString, new ParsePosition(0));
Calendar cal = Calendar.getInstance();
cal.setTime(dt);
cal.add(cal.DATE, addDays);
Date dt1 = cal.getTime();
StringBuffer strBuffer = new StringBuffer();
strBuffer.append("");
returnString = sdf.format(dt1, strBuffer, new FieldPosition(0)).toString();
}
return returnString;
}
try{
sdf.parse(strDate)
}catch(ParseException){}
try{
sdf.parse(strDate)
return true;
}catch(ParseException){
return false;
}