第一,判断日期 格式




















其中,日期字符串格式可以自己定义,以匹配你要判断的日期格式! 这里df.setLenient(false),很有用的,避免出现2007/2/31的日期向后推移
第二,显示规定的日期
public String formatToDateHourMin(Date date){
Calendar c=Calendar.getInstance();
String time="";
c.setTime(date);//
time+=c.get(Calendar.YEAR)+"/";
if((c.get(Calendar.MONTH)+1)<10)
time+="0"+(c.get(Calendar.MONTH)+1)+"/";
else
time+=(c.get(Calendar.MONTH)+1)+"/";
if(c.get(Calendar.DAY_OF_MONTH)<10)
time+="0"+c.get(Calendar.DAY_OF_MONTH)+" ";
else
time+=c.get(Calendar.DAY_OF_MONTH)+" ";
time+=c.get(Calendar.HOUR_OF_DAY)+":";//24
if(c.get(Calendar.MINUTE)<10)
time+="0"+c.get(Calendar.MINUTE);
else
time+=c.get(Calendar.MINUTE);
return time;
}
Calendar c=Calendar.getInstance();
String time="";
c.setTime(date);//
time+=c.get(Calendar.YEAR)+"/";
if((c.get(Calendar.MONTH)+1)<10)
time+="0"+(c.get(Calendar.MONTH)+1)+"/";
else
time+=(c.get(Calendar.MONTH)+1)+"/";
if(c.get(Calendar.DAY_OF_MONTH)<10)
time+="0"+c.get(Calendar.DAY_OF_MONTH)+" ";
else
time+=c.get(Calendar.DAY_OF_MONTH)+" ";
time+=c.get(Calendar.HOUR_OF_DAY)+":";//24
if(c.get(Calendar.MINUTE)<10)
time+="0"+c.get(Calendar.MINUTE);
else
time+=c.get(Calendar.MINUTE);
return time;
}
这里所显示的日期统一为2007/05/08 18:08:08
第三,把字符串转化为Date对象












这里的字符串格式dateFormat可以为yyyy/MM/dd hh:mm:ss等等!!!!
第四,计算两个日期之间的天数













通过计算毫秒数一步步得到日期间的天数,可以轻易避开月份间天数的差别
第五,判断输入是否为数字




















通过判断输入的每个字符的ASCII码是否在[48,57]之间确定数字!
第六,半角/全角的判断




















说明:checkHalf()判断字符串是否是半角。checkFull()判断字符中有多少全角字符。
第七,判断输入是否为字符和数字





















同理通过ASCII来判断