public boolean a(String s){
  try{
     java.util.Date da = new java.util.Date(s);
  }catch(Exception ex){
    return false;
  }
  return true;
}呵呵,一个比较粗鲁的做法。
也可以用Calender类来转换

解决方案 »

  1.   

    更粗鲁的做法
        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;
        }
      

  2.   

    更正 if(hours>=0&&hours<24&&minutes>=0&&minutes<60){
    呵呵
      

  3.   

    wks9527,佩服佩服,用1.1就deprecated的函数,还活在1.0里吗?
    用SimpleDateFormat.
    请回答问题也看看自己菜到什么程度,可悲。
      

  4.   

    hayai兄批评的是,我要是说错了,你只管指正。
      不过我比较傻,还不知道错在哪,为此我翻了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{}
      

  5.   

    呵呵,我还真是菜,我帖出来才看到,在构造函数里的确有这么一句:
    * @deprecated As of JDK version 1.1,
    没仔细看,看来高手就是不一样,不得不佩服