public boolean a(String s){
try{
java.util.Date da = new java.util.Date(s);
}catch(Exception ex){
return false;
}
return true;
}呵呵,一个比较粗鲁的做法。
也可以用Calender类来转换
try{
java.util.Date da = new java.util.Date(s);
}catch(Exception ex){
return false;
}
return true;
}呵呵,一个比较粗鲁的做法。
也可以用Calender类来转换
public static boolean isTime(String timeString){
try {
int hours=Integer.parseInt(timeString.substring(0,2));
int minutes=Integer.parseInt(timeString.substring(3,5));
if(hours>0&&hours<24&&minutes>0&&minutes<60){
return true;
}
}
catch (NumberFormatException ex) {
}
return false;
}
呵呵
用SimpleDateFormat.
请回答问题也看看自己菜到什么程度,可悲。
不过我比较傻,还不知道错在哪,为此我翻了jdk1.3的源码,下面是其中的一个构造函数,而parse(s));也能throw new IllegalArgumentException();想想挺合逻辑的。
我是新手,请多指正。
/**
* Allocates a <code>Date</code> object and initializes it so that
* it represents the date and time indicated by the string
* <code>s</code>, which is interpreted as if by the
* {@link Date#parse} method.
*
* @param s a string representation of the date.
* @see java.text.DateFormat
* @see java.util.Date#parse(java.lang.String)
* @deprecated As of JDK version 1.1,
* replaced by <code>DateFormat.parse(String s)</code>.
*/
public Date(String s) {
this(parse(s));
}我还找了sampleDataFormat,的确有一个方法可以达到目,帖出来大家共同学习:
/**
* Parse a date/time string.
* @param text The date/time string to be parsed
* @return A Date, or null if the input could not be parsed
* @exception ParseException If the given string cannot be parsed as a date.
* @see #parse(String, ParsePosition)
*/
public Date parse(String text) throws ParseException{}
* @deprecated As of JDK version 1.1,
没仔细看,看来高手就是不一样,不得不佩服